jenkins-bot has submitted this change and it was merged. Change subject: Avoid annotation set clones when unused ......................................................................
Avoid annotation set clones when unused Change-Id: I374ec3510344fcafa54a4bc8fe556d9db76a2ce8 --- M src/dm/ve.dm.AnnotationSet.js M src/dm/ve.dm.Converter.js 2 files changed, 44 insertions(+), 40 deletions(-) Approvals: Divec: Looks good to me, approved Jforrester: Looks good to me, but someone else must approve jenkins-bot: Verified diff --git a/src/dm/ve.dm.AnnotationSet.js b/src/dm/ve.dm.AnnotationSet.js index af61201..ec03595 100644 --- a/src/dm/ve.dm.AnnotationSet.js +++ b/src/dm/ve.dm.AnnotationSet.js @@ -36,7 +36,7 @@ * @return {ve.dm.AnnotationSet} Copy of annotation set */ ve.dm.AnnotationSet.prototype.clone = function () { - return new ve.dm.AnnotationSet( this.getStore(), this.storeIndexes.slice( 0 ) ); + return new ve.dm.AnnotationSet( this.getStore(), this.storeIndexes.slice() ); }; /** diff --git a/src/dm/ve.dm.Converter.js b/src/dm/ve.dm.Converter.js index a94ad72..5371b65 100644 --- a/src/dm/ve.dm.Converter.js +++ b/src/dm/ve.dm.Converter.js @@ -87,49 +87,53 @@ // Close annotations as needed // Go through annotationStack from bottom to top (low to high), // and find the first annotation that's not in annotations. - targetSetOpen = targetSet.clone(); - for ( i = 0, len = currentSet.getLength(); i < len; i++ ) { - index = currentSet.getIndex( i ); - // containsComparableForSerialization is expensive, - // so do a simple contains check first - if ( - targetSetOpen.containsIndex( index ) || - targetSetOpen.containsComparableForSerialization( currentSet.get( i ) ) - ) { - targetSetOpen.removeIndex( index ); - } else { - startClosingAt = i; - break; + if ( currentSet.getLength() ) { + targetSetOpen = targetSet.clone(); + for ( i = 0, len = currentSet.getLength(); i < len; i++ ) { + index = currentSet.getIndex( i ); + // containsComparableForSerialization is expensive, + // so do a simple contains check first + if ( + targetSetOpen.containsIndex( index ) || + targetSetOpen.containsComparableForSerialization( currentSet.get( i ) ) + ) { + targetSetOpen.removeIndex( index ); + } else { + startClosingAt = i; + break; + } } - } - if ( startClosingAt !== undefined ) { - // Close all annotations from top to bottom (high to low) - // until we reach startClosingAt - for ( i = currentSet.getLength() - 1; i >= startClosingAt; i-- ) { - close( currentSet.get( i ) ); - // Remove from currentClone - currentSet.removeAt( i ); + if ( startClosingAt !== undefined ) { + // Close all annotations from top to bottom (high to low) + // until we reach startClosingAt + for ( i = currentSet.getLength() - 1; i >= startClosingAt; i-- ) { + close( currentSet.get( i ) ); + // Remove from currentClone + currentSet.removeAt( i ); + } } } - currentSetOpen = currentSet.clone(); - // Open annotations as needed - for ( i = 0, len = targetSet.getLength(); i < len; i++ ) { - index = targetSet.getIndex( i ); - // containsComparableForSerialization is expensive, - // so do a simple contains check first - if ( - currentSetOpen.containsIndex( index ) || - currentSetOpen.containsComparableForSerialization( targetSet.get( i ) ) - ) { - // If an annotation is already open remove it from the currentSetOpen list - // as it may exist multiple times in the targetSet, and so may need to be - // opened again - currentSetOpen.removeIndex( index ); - } else { - open( targetSet.get( i ) ); - // Add to currentClone - currentSet.pushIndex( index ); + if ( targetSet.getLength() ) { + currentSetOpen = currentSet.clone(); + // Open annotations as needed + for ( i = 0, len = targetSet.getLength(); i < len; i++ ) { + index = targetSet.getIndex( i ); + // containsComparableForSerialization is expensive, + // so do a simple contains check first + if ( + currentSetOpen.containsIndex( index ) || + currentSetOpen.containsComparableForSerialization( targetSet.get( i ) ) + ) { + // If an annotation is already open remove it from the currentSetOpen list + // as it may exist multiple times in the targetSet, and so may need to be + // opened again + currentSetOpen.removeIndex( index ); + } else { + open( targetSet.get( i ) ); + // Add to currentClone + currentSet.pushIndex( index ); + } } } }; -- To view, visit https://gerrit.wikimedia.org/r/321021 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I374ec3510344fcafa54a4bc8fe556d9db76a2ce8 Gerrit-PatchSet: 1 Gerrit-Project: VisualEditor/VisualEditor Gerrit-Branch: master Gerrit-Owner: Esanders <esand...@wikimedia.org> Gerrit-Reviewer: DLynch <dly...@wikimedia.org> Gerrit-Reviewer: Divec <da...@troi.org> Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits