r113550 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113549‎ | r113550 | r113551 >
Date:00:31, 10 March 2012
Author:catrope
Status:deferred
Tags:
Comment:
Fix some usages of splice.apply in the data model to use
ve.batchedSplice(). Added FIXME comments for occurrences outside of DM
Modified paths:
  • /trunk/extensions/VisualEditor/demos/ce/main.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/sandbox/sandbox.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/ve/dm/ve.dm.DocumentSynchronizer.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/ve/dm/ve.dm.TransactionProcessor.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/demos/ce/main.js
@@ -625,6 +625,8 @@
626626 documentModel.data.splice( 0, documentModel.data.length );
627627 ve.insertIntoArray( documentModel.data, 0, newDocumentModel.data );
628628 surfaceModel.select( new ve.Range( 1, 1 ) );
 629+ // FIXME: this should be using ve.batchedSplice(), otherwise things
 630+ // could explode if newDocumentModel.getChildren() is very long
629631 documentModel.splice.apply(
630632 documentModel,
631633 [0, documentModel.getChildren().length]
Index: trunk/extensions/VisualEditor/modules/ve/dm/ve.dm.DocumentSynchronizer.js
@@ -86,7 +86,7 @@
8787 new ve.Range( offset, action.node.getElementLength() + action.adjustment )
8888 ) );
8989 parent = action.node.getParent();
90 - parent.splice.apply( parent, [parent.indexOf( action.node ), 1].concat( newNodes ) );
 90+ ve.batchedSplice( parent, parent.indexOf( action.node ), 1, newNodes );
9191 // Adjust proceeding offsets by the difference between the original and new nodes
9292 var newNodesLength = 0;
9393 for ( var j = 0, jlen = newNodes.length; j < jlen; j++ ) {
Index: trunk/extensions/VisualEditor/modules/ve/dm/ve.dm.TransactionProcessor.js
@@ -138,15 +138,7 @@
139139 remove--;
140140 }
141141 }
142 - // Try to perform this in a single operation if possible, this reduces the number of UI updates
143 - // TODO: Introduce a global for max argument length - 1024 is also assumed in ve.insertIntoArray
144 - if ( newNodes.length < 1024 ) {
145 - parent.splice.apply( parent, [index, remove].concat( newNodes ) );
146 - } else if ( newNodes.length ) {
147 - parent.splice.apply( parent, [index, remove] );
148 - // Safe to call with arbitrary length of newNodes
149 - ve.insertIntoArray( parent, index, newNodes );
150 - }
 142+ ve.batchedSplice( parent, index, remove, newNodes );
151143 };
152144
153145 /**
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js
@@ -467,6 +467,8 @@
468468 if( res.tokens ) {
469469 // Splice in the returned tokens (while replacing the original
470470 // token), and process them next.
 471+ // FIXME: this should be using ve.batchedSplice(), otherwise things
 472+ // could explode if res.tokens is very long
471473 [].splice.apply( tokens, [i, 1].concat(res.tokens) );
472474 tokensLength = tokens.length;
473475 i--; // continue at first inserted token
@@ -662,6 +664,8 @@
663665 if( res.tokens ) {
664666 // Splice in the returned tokens (while replacing the original
665667 // token), and process them next.
 668+ // FIXME: this should be using ve.batchedSplice(), otherwise things
 669+ // could explode if res.tokens is very long
666670 [].splice.apply( tokens, [i, 1].concat(res.tokens) );
667671 tokensLength = tokens.length;
668672 i--; // continue at first inserted token
Index: trunk/extensions/VisualEditor/modules/sandbox/sandbox.js
@@ -717,6 +717,8 @@
718718 documentModel.data.splice( 0, documentModel.data.length );
719719 ve.insertIntoArray( documentModel.data, 0, newDocumentModel.data );
720720 surfaceModel.select( new ve.Range( 1, 1 ) );
 721+ // FIXME: this should be using ve.batchedSplice(), otherwise things
 722+ // could explode if newDocumentModel.getChildren() is very long
721723 documentModel.splice.apply(
722724 documentModel,
723725 [0, documentModel.getChildren().length]

Status & tagging log