Fix some usages of splice.apply in the data model to use

ve.batchedSplice(). Added FIXME comments for occurrences outside of DM
This commit is contained in:
Roan Kattouw 2012-03-10 00:31:28 +00:00
parent 9a8f7059fc
commit 29f416937e
Notes: Roan Kattouw 2012-03-10 00:31:28 +00:00
5 changed files with 10 additions and 10 deletions

View file

@ -625,6 +625,8 @@ $(document).ready( function() {
documentModel.data.splice( 0, documentModel.data.length ); documentModel.data.splice( 0, documentModel.data.length );
ve.insertIntoArray( documentModel.data, 0, newDocumentModel.data ); ve.insertIntoArray( documentModel.data, 0, newDocumentModel.data );
surfaceModel.select( new ve.Range( 1, 1 ) ); 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.splice.apply(
documentModel, documentModel,
[0, documentModel.getChildren().length] [0, documentModel.getChildren().length]

View file

@ -467,6 +467,8 @@ AsyncTokenTransformManager.prototype.transformTokens = function ( tokens, parent
if( res.tokens ) { if( res.tokens ) {
// Splice in the returned tokens (while replacing the original // Splice in the returned tokens (while replacing the original
// token), and process them next. // 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) ); [].splice.apply( tokens, [i, 1].concat(res.tokens) );
tokensLength = tokens.length; tokensLength = tokens.length;
i--; // continue at first inserted token i--; // continue at first inserted token
@ -662,6 +664,8 @@ SyncTokenTransformManager.prototype.onChunk = function ( tokens ) {
if( res.tokens ) { if( res.tokens ) {
// Splice in the returned tokens (while replacing the original // Splice in the returned tokens (while replacing the original
// token), and process them next. // 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) ); [].splice.apply( tokens, [i, 1].concat(res.tokens) );
tokensLength = tokens.length; tokensLength = tokens.length;
i--; // continue at first inserted token i--; // continue at first inserted token

View file

@ -717,6 +717,8 @@ $(document).ready( function() {
documentModel.data.splice( 0, documentModel.data.length ); documentModel.data.splice( 0, documentModel.data.length );
ve.insertIntoArray( documentModel.data, 0, newDocumentModel.data ); ve.insertIntoArray( documentModel.data, 0, newDocumentModel.data );
surfaceModel.select( new ve.Range( 1, 1 ) ); 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.splice.apply(
documentModel, documentModel,
[0, documentModel.getChildren().length] [0, documentModel.getChildren().length]

View file

@ -86,7 +86,7 @@ ve.dm.DocumentSynchronizer.prototype.synchronize = function() {
new ve.Range( offset, action.node.getElementLength() + action.adjustment ) new ve.Range( offset, action.node.getElementLength() + action.adjustment )
) ); ) );
parent = action.node.getParent(); 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 // Adjust proceeding offsets by the difference between the original and new nodes
var newNodesLength = 0; var newNodesLength = 0;
for ( var j = 0, jlen = newNodes.length; j < jlen; j++ ) { for ( var j = 0, jlen = newNodes.length; j < jlen; j++ ) {

View file

@ -138,15 +138,7 @@ ve.dm.TransactionProcessor.prototype.rebuildNodes = function( newData, oldNodes,
remove--; remove--;
} }
} }
// Try to perform this in a single operation if possible, this reduces the number of UI updates ve.batchedSplice( parent, index, remove, newNodes );
// 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 );
}
}; };
/** /**