Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 647 }, | 647 }, |
| 648 | 648 |
| 649 next: function() | 649 next: function() |
| 650 { | 650 { |
| 651 this.node.nodeIndex = this.node._nextNodeIndex(); | 651 this.node.nodeIndex = this.node._nextNodeIndex(); |
| 652 } | 652 } |
| 653 } | 653 } |
| 654 | 654 |
| 655 | 655 |
| 656 /** | 656 /** |
| 657 * @constructor | |
| 658 */ | |
| 659 WebInspector.HeapSnapshotIndexRangeIterator = function(iterator, indexes) | |
|
alph
2014/03/20 09:58:04
annotate plz
yurys
2014/03/20 11:47:42
Done.
| |
| 660 { | |
| 661 this._iterator = iterator; | |
| 662 this._indexes = indexes; | |
| 663 this._position = 0; | |
| 664 this._forcedIndex = -1; | |
| 665 } | |
| 666 | |
| 667 WebInspector.HeapSnapshotIndexRangeIterator.prototype = { | |
| 668 /** | |
| 669 * @return {boolean} | |
| 670 */ | |
| 671 hasNext: function() | |
| 672 { | |
| 673 return this._position < this._indexes.length | |
|
alph
2014/03/20 09:58:04
; missing
yurys
2014/03/20 11:47:42
Done.
| |
| 674 }, | |
| 675 | |
| 676 /** | |
| 677 * @return {number} | |
| 678 */ | |
| 679 index: function() | |
|
loislo
2014/03/20 09:58:26
Can we just use a free function for converting ind
yurys
2014/03/20 11:47:42
We will need to pass it as a separate object as it
| |
| 680 { | |
| 681 if (this._forcedIndex !== -1) | |
| 682 return this._forcedIndex; | |
| 683 return this._indexes[this._position]; | |
| 684 }, | |
| 685 | |
| 686 /** | |
| 687 * @param {number} newIndex | |
| 688 */ | |
| 689 setIndex: function(newIndex) | |
| 690 { | |
| 691 this._forcedIndex = newIndex; | |
| 692 }, | |
| 693 | |
| 694 /** | |
| 695 * @return {!WebInspector.HeapSnapshotNode} | |
| 696 */ | |
| 697 item: function() | |
| 698 { | |
| 699 this._iterator.setIndex(this.index()); | |
| 700 return this._iterator.item(); | |
| 701 }, | |
| 702 | |
| 703 next: function() | |
| 704 { | |
| 705 ++this._position; | |
| 706 } | |
| 707 } | |
| 708 | |
| 709 | |
| 710 /** | |
| 711 * @constructor | |
| 712 */ | |
| 713 WebInspector.HeapSnapshotFilteredIterator = function(iterator, filter) | |
| 714 { | |
| 715 this._iterator = iterator; | |
| 716 this._filter = filter; | |
| 717 this._skipFilteredItems(); | |
| 718 } | |
| 719 | |
| 720 WebInspector.HeapSnapshotFilteredIterator.prototype = { | |
| 721 /** | |
| 722 * @return {boolean} | |
| 723 */ | |
| 724 hasNext: function() | |
| 725 { | |
| 726 return this._iterator.hasNext(); | |
| 727 }, | |
| 728 | |
| 729 /** | |
| 730 * @return {number} | |
| 731 */ | |
| 732 index: function() | |
| 733 { | |
| 734 return this._iterator.index(); | |
| 735 }, | |
| 736 | |
| 737 /** | |
| 738 * @param {number} newIndex | |
| 739 */ | |
| 740 setIndex: function(newIndex) | |
| 741 { | |
| 742 this._iterator.setIndex(newIndex); | |
| 743 }, | |
| 744 | |
| 745 /** | |
| 746 * @return {!WebInspector.HeapSnapshotNode} | |
| 747 */ | |
| 748 item: function() | |
| 749 { | |
| 750 return this._iterator.item(); | |
| 751 }, | |
| 752 | |
| 753 next: function() | |
| 754 { | |
| 755 this._iterator.next(); | |
| 756 this._skipFilteredItems(); | |
| 757 }, | |
| 758 | |
| 759 _skipFilteredItems: function() | |
| 760 { | |
| 761 while (this._iterator.hasNext() && !this._filter(this._iterator.item())) { | |
| 762 this._iterator.next(); | |
| 763 } | |
| 764 } | |
| 765 } | |
| 766 | |
| 767 | |
| 768 /** | |
| 657 * @param {!WebInspector.HeapSnapshotWorkerDispatcher=} dispatcher | 769 * @param {!WebInspector.HeapSnapshotWorkerDispatcher=} dispatcher |
| 658 * @constructor | 770 * @constructor |
| 659 */ | 771 */ |
| 660 WebInspector.HeapSnapshotProgress = function(dispatcher) | 772 WebInspector.HeapSnapshotProgress = function(dispatcher) |
| 661 { | 773 { |
| 662 this._dispatcher = dispatcher; | 774 this._dispatcher = dispatcher; |
| 663 } | 775 } |
| 664 | 776 |
| 665 WebInspector.HeapSnapshotProgress.prototype = { | 777 WebInspector.HeapSnapshotProgress.prototype = { |
| 666 /** | 778 /** |
| (...skipping 1218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1885 * @return {!WebInspector.HeapSnapshotCommon.StaticData} | 1997 * @return {!WebInspector.HeapSnapshotCommon.StaticData} |
| 1886 */ | 1998 */ |
| 1887 updateStaticData: function() | 1999 updateStaticData: function() |
| 1888 { | 2000 { |
| 1889 return new WebInspector.HeapSnapshotCommon.StaticData(this.nodeCount, th is._rootNodeIndex, this.totalSize, this._maxJsNodeId()); | 2001 return new WebInspector.HeapSnapshotCommon.StaticData(this.nodeCount, th is._rootNodeIndex, this.totalSize, this._maxJsNodeId()); |
| 1890 } | 2002 } |
| 1891 }; | 2003 }; |
| 1892 | 2004 |
| 1893 /** | 2005 /** |
| 1894 * @constructor | 2006 * @constructor |
| 1895 * @param {(!Array.<number>|!Uint32Array)=} unfilteredIterationOrder | |
| 1896 */ | 2007 */ |
| 1897 WebInspector.HeapSnapshotFilteredOrderedIterator = function(iterator, filter, un filteredIterationOrder) | 2008 WebInspector.HeapSnapshotFilteredOrderedIterator = function(iterator) |
|
alph
2014/03/20 09:58:04
I'd suggest drop "Filtered" from the class name.
yurys
2014/03/20 11:47:42
Done.
| |
| 1898 { | 2009 { |
| 1899 this._filter = filter; | |
| 1900 this._iterator = iterator; | 2010 this._iterator = iterator; |
| 1901 this._unfilteredIterationOrder = unfilteredIterationOrder; | 2011 this._isEmpty = !iterator.hasNext(); |
| 1902 /** @type {?Array.<number>|?Uint32Array} */ | 2012 /** @type {?Array.<number>} */ |
| 1903 this._iterationOrder = null; | 2013 this._iterationOrder = null; |
| 1904 this._position = 0; | |
| 1905 this._currentComparator = null; | 2014 this._currentComparator = null; |
| 1906 this._sortedPrefixLength = 0; | 2015 this._sortedPrefixLength = 0; |
| 1907 this._sortedSuffixLength = 0; | 2016 this._sortedSuffixLength = 0; |
| 1908 } | 2017 } |
| 1909 | 2018 |
| 1910 WebInspector.HeapSnapshotFilteredOrderedIterator.prototype = { | 2019 WebInspector.HeapSnapshotFilteredOrderedIterator.prototype = { |
| 1911 _createIterationOrder: function() | 2020 _createIterationOrder: function() |
| 1912 { | 2021 { |
| 1913 if (this._iterationOrder) | 2022 if (this._iterationOrder) |
| 1914 return; | 2023 return; |
| 1915 if (this._unfilteredIterationOrder && !this._filter) { | |
| 1916 this._iterationOrder = this._unfilteredIterationOrder; | |
| 1917 this._unfilteredIterationOrder = null; | |
| 1918 return; | |
| 1919 } | |
| 1920 this._iterationOrder = []; | 2024 this._iterationOrder = []; |
| 1921 var iterator = this._iterator; | 2025 for (var iterator = this._iterator; iterator.hasNext(); iterator.next()) |
| 1922 if (!this._unfilteredIterationOrder && !this._filter) { | 2026 this._iterationOrder.push(iterator.index()); |
| 1923 for (iterator.rewind(); iterator.hasNext(); iterator.next()) | |
| 1924 this._iterationOrder.push(iterator.index()); | |
| 1925 } else if (!this._unfilteredIterationOrder) { | |
| 1926 for (iterator.rewind(); iterator.hasNext(); iterator.next()) { | |
| 1927 if (this._filter(iterator.item())) | |
| 1928 this._iterationOrder.push(iterator.index()); | |
| 1929 } | |
| 1930 } else { | |
| 1931 var order = this._unfilteredIterationOrder; | |
| 1932 for (var i = 0, l = order.length; i < l; ++i) { | |
| 1933 iterator.setIndex(order[i]); | |
| 1934 if (this._filter(iterator.item())) | |
| 1935 this._iterationOrder.push(iterator.index()); | |
| 1936 } | |
| 1937 this._unfilteredIterationOrder = null; | |
| 1938 } | |
| 1939 }, | |
| 1940 | |
| 1941 rewind: function() | |
| 1942 { | |
| 1943 this._position = 0; | |
| 1944 }, | 2027 }, |
| 1945 | 2028 |
| 1946 /** | 2029 /** |
| 1947 * @return {boolean} | |
| 1948 */ | |
| 1949 hasNext: function() | |
| 1950 { | |
| 1951 return this._position < this._iterationOrder.length; | |
| 1952 }, | |
| 1953 | |
| 1954 /** | |
| 1955 * @return {boolean} | 2030 * @return {boolean} |
| 1956 */ | 2031 */ |
| 1957 isEmpty: function() | 2032 isEmpty: function() |
| 1958 { | 2033 { |
| 1959 if (this._iterationOrder) | 2034 return this._isEmpty; |
| 1960 return !this._iterationOrder.length; | |
| 1961 if (this._unfilteredIterationOrder && !this._filter) | |
| 1962 return !this._unfilteredIterationOrder.length; | |
| 1963 var iterator = this._iterator; | |
| 1964 if (!this._unfilteredIterationOrder && !this._filter) { | |
| 1965 iterator.rewind(); | |
| 1966 return !iterator.hasNext(); | |
| 1967 } else if (!this._unfilteredIterationOrder) { | |
| 1968 for (iterator.rewind(); iterator.hasNext(); iterator.next()) | |
| 1969 if (this._filter(iterator.item())) | |
| 1970 return false; | |
| 1971 } else { | |
| 1972 var order = this._unfilteredIterationOrder; | |
| 1973 for (var i = 0, l = order.length; i < l; ++i) { | |
| 1974 iterator.setIndex(order[i]); | |
| 1975 if (this._filter(iterator.item())) | |
| 1976 return false; | |
| 1977 } | |
| 1978 } | |
| 1979 return true; | |
| 1980 }, | 2035 }, |
| 1981 | 2036 |
| 1982 /** | 2037 /** |
| 1983 * @return {*} | |
| 1984 */ | |
| 1985 item: function() | |
| 1986 { | |
| 1987 this._iterator.setIndex(this._iterationOrder[this._position]); | |
| 1988 return this._iterator.item(); | |
| 1989 }, | |
| 1990 | |
| 1991 /** | |
| 1992 * @type {number} | |
| 1993 */ | |
| 1994 get length() | |
| 1995 { | |
| 1996 this._createIterationOrder(); | |
| 1997 return this._iterationOrder.length; | |
| 1998 }, | |
| 1999 | |
| 2000 next: function() | |
| 2001 { | |
| 2002 ++this._position; | |
| 2003 }, | |
| 2004 | |
| 2005 /** | |
| 2006 * @param {number} begin | 2038 * @param {number} begin |
| 2007 * @param {number} end | 2039 * @param {number} end |
| 2008 * @return {!WebInspector.HeapSnapshotCommon.ItemsRange} | 2040 * @return {!WebInspector.HeapSnapshotCommon.ItemsRange} |
| 2009 */ | 2041 */ |
| 2010 serializeItemsRange: function(begin, end) | 2042 serializeItemsRange: function(begin, end) |
| 2011 { | 2043 { |
| 2012 this._createIterationOrder(); | 2044 this._createIterationOrder(); |
| 2013 if (begin > end) | 2045 if (begin > end) |
| 2014 throw new Error("Start position > end position: " + begin + " > " + end); | 2046 throw new Error("Start position > end position: " + begin + " > " + end); |
| 2015 if (end > this._iterationOrder.length) | 2047 if (end > this._iterationOrder.length) |
| 2016 end = this._iterationOrder.length; | 2048 end = this._iterationOrder.length; |
| 2017 if (this._sortedPrefixLength < end && begin < this._iterationOrder.lengt h - this._sortedSuffixLength) { | 2049 if (this._sortedPrefixLength < end && begin < this._iterationOrder.lengt h - this._sortedSuffixLength) { |
| 2018 this.sort(this._currentComparator, this._sortedPrefixLength, this._i terationOrder.length - 1 - this._sortedSuffixLength, begin, end - 1); | 2050 this.sort(this._currentComparator, this._sortedPrefixLength, this._i terationOrder.length - 1 - this._sortedSuffixLength, begin, end - 1); |
| 2019 if (begin <= this._sortedPrefixLength) | 2051 if (begin <= this._sortedPrefixLength) |
| 2020 this._sortedPrefixLength = end; | 2052 this._sortedPrefixLength = end; |
| 2021 if (end >= this._iterationOrder.length - this._sortedSuffixLength) | 2053 if (end >= this._iterationOrder.length - this._sortedSuffixLength) |
| 2022 this._sortedSuffixLength = this._iterationOrder.length - begin; | 2054 this._sortedSuffixLength = this._iterationOrder.length - begin; |
| 2023 } | 2055 } |
| 2024 | 2056 var position = begin; |
| 2025 this._position = begin; | |
| 2026 var startPosition = this._position; | |
| 2027 var count = end - begin; | 2057 var count = end - begin; |
| 2028 var result = new Array(count); | 2058 var result = new Array(count); |
| 2029 for (var i = 0 ; i < count && this.hasNext(); ++i, this.next()) | 2059 var iterator = this._iterator; |
| 2030 result[i] = this.item().serialize(); | 2060 for (var i = 0 ; i < count; ++i) { |
| 2031 return new WebInspector.HeapSnapshotCommon.ItemsRange(startPosition, thi s._position, this._iterationOrder.length, result); | 2061 iterator.setIndex(this._iterationOrder[position++]); |
| 2062 result[i] = iterator.item().serialize(); | |
|
alph
2014/03/20 09:58:04
Consider joining setIndex+item into itemByIndex
yurys
2014/03/20 11:47:42
Let me address this in a separate patch.
| |
| 2063 } | |
| 2064 return new WebInspector.HeapSnapshotCommon.ItemsRange(begin, end, this._ iterationOrder.length, result); | |
| 2032 }, | 2065 }, |
| 2033 | 2066 |
| 2034 sortAndRewind: function(comparator) | 2067 sortAndRewind: function(comparator) |
| 2035 { | 2068 { |
| 2036 this._currentComparator = comparator; | 2069 this._currentComparator = comparator; |
| 2037 this._sortedPrefixLength = 0; | 2070 this._sortedPrefixLength = 0; |
| 2038 this._sortedSuffixLength = 0; | 2071 this._sortedSuffixLength = 0; |
| 2039 this.rewind(); | |
| 2040 } | 2072 } |
| 2041 } | 2073 } |
| 2042 | 2074 |
| 2043 /** | 2075 /** |
| 2044 * @constructor | 2076 * @constructor |
| 2045 * @extends {WebInspector.HeapSnapshotFilteredOrderedIterator} | 2077 * @extends {WebInspector.HeapSnapshotFilteredOrderedIterator} |
| 2046 */ | 2078 */ |
| 2047 WebInspector.HeapSnapshotEdgesProvider = function(snapshot, filter, edgesIter) | 2079 WebInspector.HeapSnapshotEdgesProvider = function(snapshot, filter, edgesIter) |
| 2048 { | 2080 { |
| 2049 this.snapshot = snapshot; | 2081 this.snapshot = snapshot; |
| 2050 WebInspector.HeapSnapshotFilteredOrderedIterator.call(this, edgesIter, filte r); | 2082 if (filter) |
| 2083 edgesIter = new WebInspector.HeapSnapshotFilteredIterator(edgesIter, fil ter); | |
| 2084 WebInspector.HeapSnapshotFilteredOrderedIterator.call(this, edgesIter); | |
| 2051 } | 2085 } |
| 2052 | 2086 |
| 2053 WebInspector.HeapSnapshotEdgesProvider.prototype = { | 2087 WebInspector.HeapSnapshotEdgesProvider.prototype = { |
| 2054 /** | 2088 /** |
| 2055 * @param {!WebInspector.HeapSnapshotCommon.ComparatorConfig} comparator | 2089 * @param {!WebInspector.HeapSnapshotCommon.ComparatorConfig} comparator |
| 2056 * @param {number} leftBound | 2090 * @param {number} leftBound |
| 2057 * @param {number} rightBound | 2091 * @param {number} rightBound |
| 2058 * @param {number} windowLeft | 2092 * @param {number} windowLeft |
| 2059 * @param {number} windowRight | 2093 * @param {number} windowRight |
| 2060 */ | 2094 */ |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2132 this._iterationOrder.sortRange(compareNodeAndNode, leftBound, rightB ound, windowLeft, windowRight); | 2166 this._iterationOrder.sortRange(compareNodeAndNode, leftBound, rightB ound, windowLeft, windowRight); |
| 2133 }, | 2167 }, |
| 2134 | 2168 |
| 2135 __proto__: WebInspector.HeapSnapshotFilteredOrderedIterator.prototype | 2169 __proto__: WebInspector.HeapSnapshotFilteredOrderedIterator.prototype |
| 2136 } | 2170 } |
| 2137 | 2171 |
| 2138 | 2172 |
| 2139 /** | 2173 /** |
| 2140 * @constructor | 2174 * @constructor |
| 2141 * @extends {WebInspector.HeapSnapshotFilteredOrderedIterator} | 2175 * @extends {WebInspector.HeapSnapshotFilteredOrderedIterator} |
| 2142 * @param {(!Array.<number>|!Uint32Array)=} nodeIndexes | 2176 * @param {?function(!WebInspector.HeapSnapshotNode):boolean} filter |
| 2177 * @param {(!Array.<number>|!Uint32Array)} nodeIndexes | |
| 2143 */ | 2178 */ |
| 2144 WebInspector.HeapSnapshotNodesProvider = function(snapshot, filter, nodeIndexes) | 2179 WebInspector.HeapSnapshotNodesProvider = function(snapshot, filter, nodeIndexes) |
| 2145 { | 2180 { |
| 2146 this.snapshot = snapshot; | 2181 this.snapshot = snapshot; |
| 2147 WebInspector.HeapSnapshotFilteredOrderedIterator.call(this, snapshot._allNod es(), filter, nodeIndexes); | 2182 var it = new WebInspector.HeapSnapshotIndexRangeIterator(snapshot._allNodes( ), nodeIndexes); |
| 2183 if (filter) | |
| 2184 it = new WebInspector.HeapSnapshotFilteredIterator(it, filter); | |
| 2185 WebInspector.HeapSnapshotFilteredOrderedIterator.call(this, it); | |
| 2148 } | 2186 } |
| 2149 | 2187 |
| 2150 WebInspector.HeapSnapshotNodesProvider.prototype = { | 2188 WebInspector.HeapSnapshotNodesProvider.prototype = { |
| 2151 /** | 2189 /** |
| 2152 * @param {string} snapshotObjectId | 2190 * @param {string} snapshotObjectId |
| 2153 * @return {number} | 2191 * @return {number} |
| 2154 */ | 2192 */ |
| 2155 nodePosition: function(snapshotObjectId) | 2193 nodePosition: function(snapshotObjectId) |
| 2156 { | 2194 { |
| 2157 this._createIterationOrder(); | 2195 this._createIterationOrder(); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2222 * @param {number} windowRight | 2260 * @param {number} windowRight |
| 2223 */ | 2261 */ |
| 2224 sort: function(comparator, leftBound, rightBound, windowLeft, windowRight) | 2262 sort: function(comparator, leftBound, rightBound, windowLeft, windowRight) |
| 2225 { | 2263 { |
| 2226 this._iterationOrder.sortRange(this._buildCompareFunction(comparator), l eftBound, rightBound, windowLeft, windowRight); | 2264 this._iterationOrder.sortRange(this._buildCompareFunction(comparator), l eftBound, rightBound, windowLeft, windowRight); |
| 2227 }, | 2265 }, |
| 2228 | 2266 |
| 2229 __proto__: WebInspector.HeapSnapshotFilteredOrderedIterator.prototype | 2267 __proto__: WebInspector.HeapSnapshotFilteredOrderedIterator.prototype |
| 2230 } | 2268 } |
| 2231 | 2269 |
| OLD | NEW |