private int walkCachingLength() {
    TreeElement cur = drillDown(this);
    while (true) {
      int length = cur.getCachedLength();
      if (length < 0) {
        // can happen only in CompositeElement
        length = 0;
        for (TreeElement child = cur.getFirstChildNode(); child != null; child = child.getTreeNext()) {
          length += child.getTextLength();
        }
        ((CompositeElement)cur).setCachedLength(length);
      }

      if (cur == this) {
        return length;
      }

      TreeElement next = cur.getTreeNext();
      cur = next != null ? drillDown(next) : getNotNullParent(cur);
    }
  }
private int walkCachingLength()