| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview Provides a system for memoizing computations applied to | 6 * @fileoverview Provides a system for memoizing computations applied to |
| 7 * DOM nodes within the same call stack. | 7 * DOM nodes within the same call stack. |
| 8 * | 8 * |
| 9 * To make a function memoizable - suppose you have a function | 9 * To make a function memoizable - suppose you have a function |
| 10 * isAccessible that takes a node and returns a boolean: | 10 * isAccessible that takes a node and returns a boolean: |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 * @constructor | 44 * @constructor |
| 45 */ | 45 */ |
| 46 cvox.Memoize = function() { | 46 cvox.Memoize = function() { |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 /** | 49 /** |
| 50 * The cache: a map from string function name to a WeakMap from DOM node | 50 * The cache: a map from string function name to a WeakMap from DOM node |
| 51 * to function result. This variable is null when we're out of scope, and it's | 51 * to function result. This variable is null when we're out of scope, and it's |
| 52 * a map from string to WeakMap to result when we're in scope. | 52 * a map from string to WeakMap to result when we're in scope. |
| 53 * | 53 * |
| 54 * @type {?Object.<string, WeakMap.<Node, *> >} | 54 * @type {?Object<string, WeakMap<Node, *> >} |
| 55 * @private | 55 * @private |
| 56 */ | 56 */ |
| 57 cvox.Memoize.nodeMap_ = null; | 57 cvox.Memoize.nodeMap_ = null; |
| 58 | 58 |
| 59 /** | 59 /** |
| 60 * Keeps track of how many nested times scope() has been called. | 60 * Keeps track of how many nested times scope() has been called. |
| 61 * @type {number} | 61 * @type {number} |
| 62 * @private | 62 * @private |
| 63 */ | 63 */ |
| 64 cvox.Memoize.scopeCount_ = 0; | 64 cvox.Memoize.scopeCount_ = 0; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 if (result === undefined) { | 124 if (result === undefined) { |
| 125 result = functionClosure(node); | 125 result = functionClosure(node); |
| 126 if (result === undefined) { | 126 if (result === undefined) { |
| 127 throw 'A memoized function cannot return undefined.'; | 127 throw 'A memoized function cannot return undefined.'; |
| 128 } | 128 } |
| 129 cvox.Memoize.nodeMap_[functionName].set(node, result); | 129 cvox.Memoize.nodeMap_[functionName].set(node, result); |
| 130 } | 130 } |
| 131 | 131 |
| 132 return result; | 132 return result; |
| 133 }; | 133 }; |
| OLD | NEW |