/* todo: perf -- optimize the number of trips through the body by ignoring the header / footer when necessary
559815
private int renderStructured() {
        if(LOGGER.isDebugEnabled() && _padContext != null)
            LOGGER.debug("\ncurrentIndex: " + _currentIndex + "\n" +
                    "checkMaxRepeat: " + _padContext.checkMaxRepeat(_currentIndex) + "\n" +
                    "checkMinRepeat: " + _padContext.checkMinRepeat(_currentIndex) + "\n");

        if(_renderState == INIT) {
            _renderState = HEADER;
            return EVAL_BODY_AGAIN;
        }

        if(_renderState == HEADER) {
            assert _renderedItems == 0;

            /* this would only happen if Pad.maxRepeat == 0 */
            if(_padContext != null && _padContext.checkMaxRepeat(_renderedItems)) {
                _renderState = FOOTER;
                return EVAL_BODY_AGAIN;
            }

            if(_currentItem == null && _ignoreNulls) {
                advanceToNonNullItem();

                /* no non-null item was found; render the footer */
                if(_currentItem == null) {
                    doPadding();
                    // render the header
                    _renderState = FOOTER;
                }
                /* non-null item found; it's not the 0th item; render it */
                else _renderState = ITEM;
            }
            /* 0th item is non-null; render it */
            else _renderState = ITEM;

            return EVAL_BODY_AGAIN;
        }

        if(_renderState == ITEM) {
            _renderedItems++;

            /* check that the maximum number of items to render has *not* been reached */
                if(_iterator.hasNext() && (_padContext == null || (_padContext != null && !_padContext.checkMaxRepeat(_renderedItems)))) {
                _currentIndex++;
                _currentItem = _iterator.next();

                if(_ignoreNulls && _currentItem == null) {
                    advanceToNonNullItem();

                    /* last item */
                    if(_currentItem == null) {
                        doPadding();

                        /* render the header */
                        _renderState = FOOTER;
                        return EVAL_BODY_AGAIN;
                    }
                }

                /* if _ignoreNulls is false, the _currentItem may be null here */
                return EVAL_BODY_AGAIN;
            }
            /*
             have finished rendering items for some reason:
              1) there isn't a next item
              2) reached the maximum number of items to render
              So:
              1) pad if necessary
              2) render the footer
             */
            else {
                doPadding();

                _renderState = FOOTER;
                return EVAL_BODY_AGAIN;
            }
        }

        if(_renderState == FOOTER) {
            _renderState = END;
            return SKIP_BODY;
        }

        return SKIP_BODY;
    }
317054
private void skip(boolean stopAtImport, boolean stopAtMemberDecl, boolean stopAtIdentifier, boolean stopAtStatement) {
         while (true) {
             switch (token.kind) {
                case SEMI:
                    nextToken();
                    return;
                case PUBLIC:
                case FINAL:
                case ABSTRACT:
                case MONKEYS_AT:
                case EOF:
                case CLASS:
                case INTERFACE:
                case ENUM:
                    return;
                case IMPORT:
                    if (stopAtImport)
                        return;
                    break;
                case LBRACE:
                case RBRACE:
                case PRIVATE:
                case PROTECTED:
                case STATIC:
                case TRANSIENT:
                case NATIVE:
                case VOLATILE:
                case SYNCHRONIZED:
                case STRICTFP:
                case LT:
                case BYTE:
                case SHORT:
                case CHAR:
                case INT:
                case LONG:
                case FLOAT:
                case DOUBLE:
                case BOOLEAN:
                case VOID:
                    if (stopAtMemberDecl)
                        return;
                    break;
                case UNDERSCORE:
                case IDENTIFIER:
                   if (stopAtIdentifier)
                        return;
                    break;
                case CASE:
                case DEFAULT:
                case IF:
                case FOR:
                case WHILE:
                case DO:
                case TRY:
                case SWITCH:
                case RETURN:
                case THROW:
                case BREAK:
                case CONTINUE:
                case ELSE:
                case FINALLY:
                case CATCH:
                    if (stopAtStatement)
                        return;
                    break;
            }
            nextToken();
        }
    }
953434
protected URL getRoutingStrategyDestination(Object request, Map<String,String> headers) {
        for (RequestRoutingStrategy routingStrategy : MdwServiceRegistry.getInstance().getRequestRoutingStrategies()) {
            URL destination = routingStrategy.getDestination(request, headers);
            if (destination != null) {
                // Only return a destination if it is not itself (identical call) - Avoid infinite loop
         //       int queryIdx = destination.toString().indexOf("?");
                URL origRequestUrl = null;
                try {
                    origRequestUrl = new URL(headers.get(Listener.METAINFO_REQUEST_URL));
                }
                catch (MalformedURLException e) {
                    logger.severeException("Malformed original RequestURL", e);
                }
                String origHost = origRequestUrl.getHost().indexOf(".") > 0 ? origRequestUrl.getHost().substring(0, origRequestUrl.getHost().indexOf(".")) : origRequestUrl.getHost();
                int origPort = origRequestUrl.getPort() == 80 || origRequestUrl.getPort() == 443 ? -1 : origRequestUrl.getPort();
                String origQuery = headers.get(Listener.METAINFO_REQUEST_QUERY_STRING) == null ? "" : headers.get(Listener.METAINFO_REQUEST_QUERY_STRING);
                String newHost = destination.getHost().indexOf(".") > 0 ? destination.getHost().substring(0, destination.getHost().indexOf(".")) : destination.getHost();
                int newPort = destination.getPort() == 80 || destination.getPort() == 443 ? -1 : destination.getPort();
                String newQuery = destination.getQuery() == null ? "" : destination.getQuery();

                if (!newHost.equalsIgnoreCase(origHost) || !(newPort == origPort) || !newQuery.equalsIgnoreCase(origQuery) || !origRequestUrl.getPath().equals(destination.getPath()))
                    return destination;
            }
        }
        return null;
    }
1331425
public final void notifyFooterItemRangeInserted(int positionStart, int itemCount) {
        int newHeaderItemCount = getHeaderItemCount();
        int newContentItemCount = getContentItemCount();
        int newFooterItemCount = getFooterItemCount();
        if (positionStart < 0 || itemCount < 0 || positionStart + itemCount > newFooterItemCount) {
            throw new IndexOutOfBoundsException("The given range [" + positionStart + " - "
                    + (positionStart + itemCount - 1) + "] is not within the position bounds for footer items [0 - "
                    + (newFooterItemCount - 1) + "].");
        }
        notifyItemRangeInserted(positionStart + newHeaderItemCount + newContentItemCount, itemCount);
    }
847864
function () {
            var $pages = this.$pages,
                index = this.state.currentPage - 1,
                next = index + 1,
                prev = index - 1,
                buffer = 20;

            // @TODO: optimize this a bit
            // add/removeClass is expensive, so try using hasClass
            $pages.removeClass(PRESENTATION_CSS_CLASSES);
            if (this.twoPageMode) {
                next = index + 2;
                prev = index - 2;
                $pages.slice(Math.max(prev, 0), index).addClass(CSS_CLASS_PAGE_PREV);
                $pages.slice(next, next + 2).addClass(CSS_CLASS_PAGE_NEXT);
            } else {
                if (prev >= 0) {
                    $pages.eq(prev).addClass(CSS_CLASS_PAGE_PREV);
                }
                if (next < this.numPages) {
                    $pages.eq(next).addClass(CSS_CLASS_PAGE_NEXT);
                }
            }
            $pages.slice(0, index).addClass(CSS_CLASS_PAGE_BEFORE);
            $pages.slice(Math.max(0, index - buffer), index).addClass(CSS_CLASS_PAGE_BEFORE_BUFFER);
            $pages.slice(next).addClass(CSS_CLASS_PAGE_AFTER);
            $pages.slice(next, Math.min(this.numPages, next + buffer)).addClass(CSS_CLASS_PAGE_AFTER_BUFFER);

            /*
            // OPTIMIZATION CODE NOT YET WORKING PROPERLY
            $pages.slice(0, index).each(function () {
                var $p = $(this),
                    i = $p.index(),
                    toAdd = '',
                    toRm = '';
                if (!$p.hasClass(beforeClass.trim())) toAdd += beforeClass;
                if ($p.hasClass(nextClass.trim())) toRm += nextClass;
                if ($p.hasClass(afterClass.trim())) toRm += afterClass;
                if ($p.hasClass(afterBufferClass.trim())) toRm += afterBufferClass;
                if (i >= index - buffer && !$p.hasClass(beforeBufferClass.trim()))
                    toAdd += beforeBufferClass;
                else if ($p.hasClass(beforeBufferClass.trim()))
                    toRm += beforeBufferClass;
                if (i >= prev && !$p.hasClass(prevClass.trim()))
                    toAdd += prevClass;
                else if ($p.hasClass(prevClass.trim()))
                    toRm += prevClass;
                $p.addClass(toAdd).removeClass(toRm);
//                console.log('before', $p.index(), toRm, toAdd);
            });
            $pages.slice(next).each(function () {
                var $p = $(this),
                    i = $p.index(),
                    toAdd = '',
                    toRm = '';
                if (!$p.hasClass(afterClass.trim())) toAdd += afterClass;
                if ($p.hasClass(prevClass.trim())) toRm += prevClass;
                if ($p.hasClass(beforeClass.trim())) toRm += beforeClass;
                if ($p.hasClass(beforeBufferClass.trim())) toRm += beforeBufferClass;
                if (i <= index + buffer && !$p.hasClass(afterBufferClass.trim()))
                    toAdd += afterBufferClass;
                else if ($p.hasClass(afterBufferClass.trim()))
                    toRm += afterBufferClass;
                if (i <= next + 1 && !$p.hasClass(nextClass.trim()))
                    toAdd += nextClass;
                else if ($p.hasClass(nextClass.trim()))
                    toRm += nextClass;
                $p.addClass(toAdd).removeClass(toRm);
//                console.log('after', $p.index(), toRm, toAdd);
            });*/
        }
914067
function HeaderEntry(hash, height) {
  this.hash = hash;
  this.height = height;
  this.prev = null;
  this.next = null;
}
775474
protected void prepareForwardedRequestHeaders(RequestData request, ForwardDestination destination) {
        HttpHeaders headers = request.getHeaders();
        headers.set(HOST, destination.getUri().getAuthority());
        headers.remove(TE);
    }
134910
public void setHeaderFooter(RtfHeaderFooter headerFooter, int displayAt) {
        this.mode = MODE_MULTIPLE;
        headerFooter.setRtfDocument(this.document);
        headerFooter.setType(this.type);
        headerFooter.setDisplayAt(displayAt);
        switch(displayAt) {
            case RtfHeaderFooter.DISPLAY_ALL_PAGES:
                headerAll = headerFooter;
            	break;
            case RtfHeaderFooter.DISPLAY_FIRST_PAGE:
                headerFirst = headerFooter;
                break;
            case RtfHeaderFooter.DISPLAY_LEFT_PAGES:
                headerLeft = headerFooter;
                break;
            case RtfHeaderFooter.DISPLAY_RIGHT_PAGES:
                headerRight = headerFooter;
                break;
        }
    }
978129
private void skipPayload(int numBytes)
            throws IOException
    {
        while (true) {
            int bufferRemaining = buffer.size() - position;
            if (bufferRemaining >= numBytes) {
                position += numBytes;
                return;
            }
            else {
                position += bufferRemaining;
                numBytes -= bufferRemaining;
            }
            nextBuffer();
        }
    }
698472
private void fillHeader()
  {
    byte[] buffer = _indexBuffer;
    
    Arrays.fill(buffer, (byte) 0x0);
    
    int index = 0;
    
    BitsUtil.writeLong(buffer, index, _segment.getSequence());
    index += 8;
    
    byte []tableKey = _table.tableKey();
    System.arraycopy(tableKey, 0, buffer, index, tableKey.length);
    index += tableKey.length;

    /*
    BitsUtil.writeInt16(buffer, index, tail);
    index += 2;
  
    buffer[index] = (byte) (isCont ? 1 : 0);
    index++;
    */
    
    _indexTail = index;
    
    fillFooter(buffer, FOOTER_OFFSET, index, false);
  }
539052
function furkotTrip() {
  var form, stops;

  function plan(data) {
    if (!form) {
      form = createForm();
    }
    stops.value = JSON.stringify(data);
    return form.submit();
  }

  function getUrl(data) {
    if (data) {
      if (Array.isArray(data)) {
        data = data.map(function (stop, i) {
          return toQuery(stop, 'stops[' + i + ']');
        }).join('&');
      }
      else {
        data = toQuery(data, 'stop');
      }
      if (data) {
        data = '?' + data;
      }
    }
    return destination + (data || '');
  }

  function toQuery(data, prefix) {
    return Object.keys(data).map(toParam, {
      data: data,
      prefix: prefix
    }).join('&');
  }

  function toParam(key) {
    var data = this.data, prefix = this.prefix + '[' + key + ']';
    if (typeof data[key] === 'object') {
      return toQuery(data[key], prefix);
    }
    return [prefix, encodeURIComponent(data[key] || '')].join('=');
  }

  function target() {
    var hidden = window.locationbar && !window.locationbar.visible;
    return hidden ? '_blank' : '_top';
  }

  function createForm() {
    var form = document.createElement('form');
    form.style.display = 'none';
    form.action = destination;
    form.method = 'post';
    form.target = target();
    stops = document.createElement('input');
    stops.name = 'stops';
    form.appendChild(stops);
    // Firefox needs form in DOM
    document.body.appendChild(form);
    return form;
  }

  return {
    plan: plan,
    getUrl: getUrl
  };
}
864858
def _prior_headerfooter(self):
        """"""
        preceding_sectPr = self._sectPr.preceding_sectPr
        return (
            None if preceding_sectPr is None
            else _Header(preceding_sectPr, self._document_part, self._hdrftr_index)
        )
1200686
function () {

			var headersLength = sourceHeaders.length;
			var minDistance = Number.MAX_VALUE;
			var closestHeader = -1;
			var fileNameInUrl = filename === '' ? '' : filename + '.' +  extension;

			if ((document.body.scrollTop || document.documentElement.scrollTop) < hashThreshold) {

				if (!!window.location.hash)	{
					currentHeader = -1;
					if (!!(window.history && history.pushState)) {
						window.history.replaceState({anchor: 0}, document.title, window.location.pathname);
					}
				}

				return;
			}

			// catch section which is closed for top window border
			for (var i=0; i < headersLength; i++) {

				if ((sourceHeaders[i].tagName === 'H3') && (!utils.hasClass(utils.closest(sourceHeaders[i], 'source_section'), 'source_section__open')) ) {
					continue;
				}

				var currentDist = Math.abs( utils.offsetTop(sourceHeaders[i]) - 60 - window.pageYOffset ); //60 = Header heights
				if (currentDist < minDistance) {
					closestHeader = i;
					minDistance = currentDist;
				}
			}

			if (closestHeader !== currentHeader) {
				utils.removeClass( document.querySelector('.source_main_nav_li.__active'), '__active');
				utils.removeClass( document.querySelector('.source_main_nav_a.__active'), '__active');

				utils.addClass(navHeaders[closestHeader], '__active');

				var parent = utils.closest(navHeaders[closestHeader], 'source_main_nav_li');
				var hashFromLink = navHeaders[closestHeader].getAttribute('href');

				if (!!parent && parent) {
					utils.addClass(parent, '__active');
				}

				if (_this.conf.updateHash) {
					// TODO: pause hash change when scrolling - append it only on stand-still

					// Modern browsers uses history API for correct back-button-browser functionality
					if (!!(window.history && history.pushState)) {
						window.history.replaceState({anchor: closestHeader+1}, document.title, fileNameInUrl + hashFromLink);
					} else { // ie9 fallback
						 window.location.hash = hashFromLink;
					}
				}

				currentHeader = closestHeader;
			}
		}
743620
function perfFindInterlacedRemoves() {
  var start, end;
  var totalTimes = [];
  var totalMS = 0;

  for (var idx = 0; idx < arraySize; idx++) {
    //var customidx = Math.floor(Math.random() * arraySize) + 1;

    start = process.hrtime();
    var result = samplecoll.findOne({
      'customId': idx
    });
    // remove document now (outside timing routine) to force index rebuild
    samplecoll.remove(result); 
    
    end = process.hrtime(start);
    totalTimes.push(end);
  }

  for (var idx = 0; idx < totalTimes.length; idx++) {
    totalMS += totalTimes[idx][0] * 1e3 + totalTimes[idx][1] / 1e6;
  }

  totalMS = totalMS.toFixed(2);
  var rate = arraySize * 1000 / totalMS;
  rate = rate.toFixed(2);
  console.log("interlaced removes + coll.find() : " + totalMS + "ms (" + rate + " ops/s) " + arraySize + " iterations");
}
1251782
function pruneHeaders(requestHeaders) {
  const headers = Object.assign({}, requestHeaders);

  delete headers.trackingid;
  delete headers.authorization;

  return headers;
}
856204
function perfmon() {
	var inputs = parseInputs(arguments);
	var pstream = new PerfmonStream(inputs.options.counters);

	if (typeof(inputs.cb) == 'function') {
		pstream.on('data', function(data) {
			inputs.cb(null, data);
		});

		pstream.on('error', inputs.cb);
	}

	if (inputs.options.error) {
		process.nextTick(function() {
			pstream.emit('error', inputs.options.error);
		});
	}
	else {
		inputs.options.hosts.forEach(function(h) {
			init(h, inputs.options, pstream);
		});	
	}

	return pstream;
}
790106
function cleanSingleHeader(e) {
  for (var headerIndex = 1; headerIndex < 7; headerIndex++) {
    var headers = e.getElementsByTagName('h' + headerIndex);
    for (var i = headers.length - 1; i >= 0; --i) {
      if (headers[i].nextSibling === null) {
        headers[i].parentNode.removeChild(headers[i]);
      }
    }
  }

}