OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 * if (parentClone) | 388 * if (parentClone) |
389 * parentClone.addChild(nodeClone); | 389 * parentClone.addChild(nodeClone); |
390 * return nodeClone; | 390 * return nodeClone; |
391 * }); | 391 * }); |
392 * | 392 * |
393 * @param {function(devtools.profiler.CallTree.Node, *)} f Visitor function. | 393 * @param {function(devtools.profiler.CallTree.Node, *)} f Visitor function. |
394 * The second parameter is the result of calling 'f' on the parent node. | 394 * The second parameter is the result of calling 'f' on the parent node. |
395 * @param {devtools.profiler.CallTree.Node} opt_start Starting node. | 395 * @param {devtools.profiler.CallTree.Node} opt_start Starting node. |
396 */ | 396 */ |
397 devtools.profiler.CallTree.prototype.traverse = function(f, opt_start) { | 397 devtools.profiler.CallTree.prototype.traverse = function(f, opt_start) { |
398 var pairsToProcess = [{node: opt_start || this.root_, param: null}]; | 398 var pairsToProcess = new ConsArray(); |
399 while (pairsToProcess.length > 0) { | 399 pairsToProcess.concat([{node: opt_start || this.root_, param: null}]); |
400 var pair = pairsToProcess.shift(); | 400 while (!pairsToProcess.atEnd()) { |
| 401 var pair = pairsToProcess.next(); |
401 var node = pair.node; | 402 var node = pair.node; |
402 var newParam = f(node, pair.param); | 403 var newParam = f(node, pair.param); |
403 node.forEachChild( | 404 var morePairsToProcess = []; |
404 function (child) { pairsToProcess.push({node: child, param: newParam}); } | 405 node.forEachChild(function (child) { |
405 ); | 406 morePairsToProcess.push({node: child, param: newParam}); }); |
| 407 pairsToProcess.concat(morePairsToProcess); |
406 } | 408 } |
407 }; | 409 }; |
408 | 410 |
409 | 411 |
410 /** | 412 /** |
411 * Performs an indepth call graph traversal. | 413 * Performs an indepth call graph traversal. |
412 * | 414 * |
413 * @param {function(devtools.profiler.CallTree.Node)} enter A function called | 415 * @param {function(devtools.profiler.CallTree.Node)} enter A function called |
414 * prior to visiting node's children. | 416 * prior to visiting node's children. |
415 * @param {function(devtools.profiler.CallTree.Node)} exit A function called | 417 * @param {function(devtools.profiler.CallTree.Node)} exit A function called |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 labels, opt_f) { | 547 labels, opt_f) { |
546 for (var pos = 0, curr = this; pos < labels.length && curr != null; pos++) { | 548 for (var pos = 0, curr = this; pos < labels.length && curr != null; pos++) { |
547 var child = curr.findChild(labels[pos]); | 549 var child = curr.findChild(labels[pos]); |
548 if (opt_f) { | 550 if (opt_f) { |
549 opt_f(child, pos); | 551 opt_f(child, pos); |
550 } | 552 } |
551 curr = child; | 553 curr = child; |
552 } | 554 } |
553 return curr; | 555 return curr; |
554 }; | 556 }; |
OLD | NEW |