r98934 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98933‎ | r98934 | r98935 >
Date:22:00, 4 October 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Removed bad caching approach
Modified paths:
  • /trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js
@@ -20,13 +20,6 @@
2121 // Initialization
2222 node.rebuildChildNodes();
2323
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 -
3124 return node;
3225 };
3326
@@ -259,9 +252,8 @@
260253 /**
261254 * Gets the content offset of a node.
262255 *
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.
266258 *
267259 * @method
268260 * @param {es.DocumentModelNode} node Node to get offset of
@@ -273,22 +265,15 @@
274266 if ( from === undefined ) {
275267 from = this;
276268 }
277 - var cachedOffset = this.offsetCache.indexOf( node );
278 - if ( cachedOffset !== -1 ) {
279 - return cachedOffset;
280 - }
281269 var offset = 0;
282270 for ( var i = 0; i < from.length; i++ ) {
283271 if ( node === from[i] ) {
284 - this.offsetCache[offset] = node;
285272 return offset;
286273 }
287274 if ( deep && from[i].length ) {
288275 var length = this.offsetOf( node, true, from[i] );
289276 if ( length !== -1 ) {
290 - offset += length;
291 - this.offsetCache[offset] = node;
292 - return offset;
 277+ return offset + length;
293278 }
294279 }
295280 offset += from[i].getElementLength();

Status & tagging log