diff --git a/modules/ve/dm/ve.dm.Document.js b/modules/ve/dm/ve.dm.Document.js index 80df2e5bbe..67430b94e4 100644 --- a/modules/ve/dm/ve.dm.Document.js +++ b/modules/ve/dm/ve.dm.Document.js @@ -8,6 +8,13 @@ /** * DataModel document. * + * WARNING: Data passed into a new document will be sliced, creating a shallow copy. This is done to + * prevent multiple documents sharing references to the same data, which causes very strange and + * difficult to diagnose issues. By slicing by default, this issue is dealt with automatically. This + * comes at a price however. While a slice is much faster than a deep copy, it may still be a + * problem with really big data sets. We do not know that this is an issue yet, but consider it a + * likely area to cause performance problems in the future. + * * @class * @extends {ve.Document} * @constructor @@ -20,7 +27,7 @@ ve.dm.Document = function ( data, parentDocument ) { // Properties this.parentDocument = parentDocument; - this.data = data || []; + this.data = ve.isArray( data ) ? data.slice( 0 ) : []; // Initialization /* diff --git a/modules/ve/test/dm/ve.dm.Document.test.js b/modules/ve/test/dm/ve.dm.Document.test.js index ddd150f47b..70a286f17c 100644 --- a/modules/ve/test/dm/ve.dm.Document.test.js +++ b/modules/ve/test/dm/ve.dm.Document.test.js @@ -898,7 +898,7 @@ QUnit.test( 'isContentData', 1, function ( assert ) { QUnit.test( 'rebuildNodes', function ( assert ) { var tree, - doc = new ve.dm.Document( ve.dm.example.data.slice( 0 ) ), + doc = new ve.dm.Document( ve.dm.example.data ), documentNode = doc.getDocumentNode(); // Rebuild table without changes doc.rebuildNodes( documentNode, 1, 1, 5, 32 ); diff --git a/modules/ve/test/dm/ve.dm.DocumentSynchronizer.test.js b/modules/ve/test/dm/ve.dm.DocumentSynchronizer.test.js index 937ad51b39..47e281150a 100644 --- a/modules/ve/test/dm/ve.dm.DocumentSynchronizer.test.js +++ b/modules/ve/test/dm/ve.dm.DocumentSynchronizer.test.js @@ -10,13 +10,13 @@ QUnit.module( 've.dm.DocumentSynchronizer' ); /* Tests */ QUnit.test( 'getDocument', 1, function ( assert ) { - var doc = new ve.dm.Document( ve.dm.example.data.slice( 0 ) ), + var doc = new ve.dm.Document( ve.dm.example.data ), ds = new ve.dm.DocumentSynchronizer( doc ); assert.strictEqual( ds.getDocument(), doc ); } ); QUnit.test( 'synchronize', 2, function ( assert ) { - var doc = new ve.dm.Document( ve.dm.example.data.slice( 0 ) ), + var doc = new ve.dm.Document( ve.dm.example.data ), ds = new ve.dm.DocumentSynchronizer( doc ); // Annotate "a" with bold formatting