CXOptimizeCollector/JavaScriptCollector/Boomerang/Plugins/restiming.js
/**
	 * Optimize the Trie by combining branches with no leaf
	 *
	 * @param [object] cur Current Trie branch
	 * @param [boolean] top Whether or not this is the root node
	 */
Optimize the Trie by combining branches with no leaf
@param [object] cur Current Trie branch
@param [boolean] top Whether or not this is the root node
Optimize the Trie by combining branches with no leaf @param [ object ] cur Current Trie branch @param [ boolean ] top Whether or not this is the root node
function optimizeTrie(cur, top) {
		var num = 0, node, ret, topNode;
		var keys = [];
		for (node in cur) {
			if (cur.hasOwnProperty(node)) {
				keys.push(node);
			}
		}
		for (var i = 0; i < keys.length; i++) {
			node = keys[i];
			if (typeof cur[node] === "object") {
				ret = optimizeTrie(cur[node], false);
				if (ret) {
					delete cur[node];
					if (node === XSS_BREAK_DELIM) {
						node = ret.name;
						num++;
					}
					else {
						node = node + ret.name;
					}
					cur[node] = ret.value;
				}
			}
			num++;
		}
		if (num === 1) {
			if (top) {
				topNode = {};
				topNode[node] = cur[node];
				return topNode;
			}
			else {
				return { name: node, value: cur[node] };
			}
		}
		else if (top) {
			return cur;
		}
		else {
			return false;
		}
	}
function optimizeTrie ( cur , top ) { var num = 0 , node , ret , topNode ; var keys = [ ] ; for ( node in cur ) { if ( cur . hasOwnProperty ( node ) ) { keys . push ( node ) ; } } for ( var i = 0 ; i < keys . length ; i ++ ) { node = keys [ i ] ; if ( typeof cur [ node ] === "object" ) { ret = optimizeTrie ( cur [ node ] , false ) ; if ( ret ) { delete cur [ node ] ; if ( node === XSS_BREAK_DELIM ) { node = ret . name ; num ++ ; } else { node = node + ret . name ; } cur [ node ] = ret . value ; } } num ++ ; } if ( num === 1 ) { if ( top ) { topNode = { } ; topNode [ node ] = cur [ node ] ; return topNode ; } else { return { name : node , value : cur [ node ] } ; } } else if ( top ) { return cur ; } else { return false ; } }
Optimize the Trie by combining branches with no leaf
 @param [object] cur Current Trie branch
 @param [boolean] top Whether or not this is the root node
Optimize the Trie by combining branches with no leaf @param [ object ] cur Current Trie branch @param [ boolean ] top Whether or not this is the root node
// capture trie keys first as we'll be modifying it // optimize children // swap the current leaf with compressed one // If this node is a newline, which can't be in a regular URL, // it's due to the XSS patch.  Remove the placeholder character, // and make sure this node isn't compressed by incrementing // num to be greater than one. // compress single leafs // top node gets special treatment so we're not left with a {node:,value:} at top // other nodes we return name and value separately // top node with more than 1 child, return it as-is // more than two nodes and not the top, we can't compress any more