https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113550
Revision: 113550
Author: catrope
Date: 2012-03-10 00:31:28 +0000 (Sat, 10 Mar 2012)
Log Message:
-----------
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
trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js
trunk/extensions/VisualEditor/modules/sandbox/sandbox.js
trunk/extensions/VisualEditor/modules/ve/dm/ve.dm.DocumentSynchronizer.js
trunk/extensions/VisualEditor/modules/ve/dm/ve.dm.TransactionProcessor.js
Modified: trunk/extensions/VisualEditor/demos/ce/main.js
===================================================================
--- trunk/extensions/VisualEditor/demos/ce/main.js 2012-03-09 23:53:10 UTC
(rev 113549)
+++ trunk/extensions/VisualEditor/demos/ce/main.js 2012-03-10 00:31:28 UTC
(rev 113550)
@@ -625,6 +625,8 @@
documentModel.data.splice( 0, documentModel.data.length );
ve.insertIntoArray(
documentModel.data, 0, newDocumentModel.data );
surfaceModel.select(
new ve.Range( 1, 1 ) );
+ // FIXME: this should
be using ve.batchedSplice(), otherwise things
+ // could explode if
newDocumentModel.getChildren() is very long
documentModel.splice.apply(
documentModel,
[0,
documentModel.getChildren().length]
Modified:
trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js
===================================================================
---
trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js
2012-03-09 23:53:10 UTC (rev 113549)
+++
trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js
2012-03-10 00:31:28 UTC (rev 113550)
@@ -467,6 +467,8 @@
if( res.tokens ) {
// Splice in the returned tokens (while replacing the
original
// token), and process them next.
+ // FIXME: this should be using ve.batchedSplice(),
otherwise things
+ // could explode if res.tokens is very long
[].splice.apply( tokens, [i, 1].concat(res.tokens) );
tokensLength = tokens.length;
i--; // continue at first inserted token
@@ -662,6 +664,8 @@
if( res.tokens ) {
// Splice in the returned tokens (while replacing the
original
// token), and process them next.
+ // FIXME: this should be using ve.batchedSplice(),
otherwise things
+ // could explode if res.tokens is very long
[].splice.apply( tokens, [i, 1].concat(res.tokens) );
tokensLength = tokens.length;
i--; // continue at first inserted token
Modified: trunk/extensions/VisualEditor/modules/sandbox/sandbox.js
===================================================================
--- trunk/extensions/VisualEditor/modules/sandbox/sandbox.js 2012-03-09
23:53:10 UTC (rev 113549)
+++ trunk/extensions/VisualEditor/modules/sandbox/sandbox.js 2012-03-10
00:31:28 UTC (rev 113550)
@@ -717,6 +717,8 @@
documentModel.data.splice( 0, documentModel.data.length );
ve.insertIntoArray(
documentModel.data, 0, newDocumentModel.data );
surfaceModel.select(
new ve.Range( 1, 1 ) );
+ // FIXME: this should
be using ve.batchedSplice(), otherwise things
+ // could explode if
newDocumentModel.getChildren() is very long
documentModel.splice.apply(
documentModel,
[0,
documentModel.getChildren().length]
Modified:
trunk/extensions/VisualEditor/modules/ve/dm/ve.dm.DocumentSynchronizer.js
===================================================================
--- trunk/extensions/VisualEditor/modules/ve/dm/ve.dm.DocumentSynchronizer.js
2012-03-09 23:53:10 UTC (rev 113549)
+++ trunk/extensions/VisualEditor/modules/ve/dm/ve.dm.DocumentSynchronizer.js
2012-03-10 00:31:28 UTC (rev 113550)
@@ -86,7 +86,7 @@
new ve.Range( offset,
action.node.getElementLength() + action.adjustment )
) );
parent = action.node.getParent();
- parent.splice.apply( parent, [parent.indexOf(
action.node ), 1].concat( newNodes ) );
+ ve.batchedSplice( parent, parent.indexOf(
action.node ), 1, newNodes );
// Adjust proceeding offsets by the difference
between the original and new nodes
var newNodesLength = 0;
for ( var j = 0, jlen = newNodes.length; j <
jlen; j++ ) {
Modified:
trunk/extensions/VisualEditor/modules/ve/dm/ve.dm.TransactionProcessor.js
===================================================================
--- trunk/extensions/VisualEditor/modules/ve/dm/ve.dm.TransactionProcessor.js
2012-03-09 23:53:10 UTC (rev 113549)
+++ trunk/extensions/VisualEditor/modules/ve/dm/ve.dm.TransactionProcessor.js
2012-03-10 00:31:28 UTC (rev 113550)
@@ -138,15 +138,7 @@
remove--;
}
}
- // Try to perform this in a single operation if possible, this reduces
the number of UI updates
- // TODO: Introduce a global for max argument length - 1024 is also
assumed in ve.insertIntoArray
- if ( newNodes.length < 1024 ) {
- parent.splice.apply( parent, [index, remove].concat( newNodes )
);
- } else if ( newNodes.length ) {
- parent.splice.apply( parent, [index, remove] );
- // Safe to call with arbitrary length of newNodes
- ve.insertIntoArray( parent, index, newNodes );
- }
+ ve.batchedSplice( parent, index, remove, newNodes );
};
/**
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs