Index: trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js |
— | — | @@ -20,13 +20,6 @@ |
21 | 21 | // Initialization |
22 | 22 | node.rebuildChildNodes(); |
23 | 23 | |
24 | | - // Sparse array of offsets and nodes located at those offsets |
25 | | - node.offsetCache = []; |
26 | | - node.on( 'update', function() { |
27 | | - // Clear offset cache when content is changed |
28 | | - node.offsetCache = []; |
29 | | - } ); |
30 | | - |
31 | 24 | return node; |
32 | 25 | }; |
33 | 26 | |
— | — | @@ -259,9 +252,8 @@ |
260 | 253 | /** |
261 | 254 | * Gets the content offset of a node. |
262 | 255 | * |
263 | | - * This method uses a cache (this.offsetCache) to make repeated lookups for the same node quicker, |
264 | | - * but this cache is cleared when the document is updated, so be careful to consolidate update |
265 | | - * events if possible when depending on this method to be fast. |
| 256 | + * This method is pretty expensive. If you need to get different slices of the same content, get |
| 257 | + * the content first, then slice it up locally. |
266 | 258 | * |
267 | 259 | * @method |
268 | 260 | * @param {es.DocumentModelNode} node Node to get offset of |
— | — | @@ -273,22 +265,15 @@ |
274 | 266 | if ( from === undefined ) { |
275 | 267 | from = this; |
276 | 268 | } |
277 | | - var cachedOffset = this.offsetCache.indexOf( node ); |
278 | | - if ( cachedOffset !== -1 ) { |
279 | | - return cachedOffset; |
280 | | - } |
281 | 269 | var offset = 0; |
282 | 270 | for ( var i = 0; i < from.length; i++ ) { |
283 | 271 | if ( node === from[i] ) { |
284 | | - this.offsetCache[offset] = node; |
285 | 272 | return offset; |
286 | 273 | } |
287 | 274 | if ( deep && from[i].length ) { |
288 | 275 | var length = this.offsetOf( node, true, from[i] ); |
289 | 276 | if ( length !== -1 ) { |
290 | | - offset += length; |
291 | | - this.offsetCache[offset] = node; |
292 | | - return offset; |
| 277 | + return offset + length; |
293 | 278 | } |
294 | 279 | } |
295 | 280 | offset += from[i].getElementLength(); |