jenkins-bot has submitted this change and it was merged.
Change subject: Small cleanup/refactoring to getSiblingWordBoundary
......................................................................
Small cleanup/refactoring to getSiblingWordBoundary
CPU time + memory optimization + make inexpensive comparison first
Change-Id: I7f504f741b4d90201e40bbc40ae2e88fe0db2e33
---
M modules/ve/ce/ve.ce.Document.js
1 file changed, 10 insertions(+), 20 deletions(-)
Approvals:
Christian: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/ve/ce/ve.ce.Document.js b/modules/ve/ce/ve.ce.Document.js
index 79fd18a..c7ea4db 100644
--- a/modules/ve/ce/ve.ce.Document.js
+++ b/modules/ve/ce/ve.ce.Document.js
@@ -93,36 +93,25 @@
data = this.model.data,
i = direction > 0 ? offset : offset - 1,
inc = direction > 0 ? 1 : -1,
- prevChar, nextChar, prevType, nextType;
-
- config = $.browser.msie ? config.ie : config.default;
- config = direction > 0 ? config.right : config.left;
-
+ oneChar, prevType, nextType;
if ( !data[i] || data[i].type !== undefined ) {
return this.model.getRelativeContentOffset( offset, direction );
} else {
- prevChar = typeof data[i] === 'string' ? data[i] : data[i][0];
- if ( !pattern.test( prevChar ) ) {
- prevType = 'text';
- } else if ( prevChar !== ' ' ) {
- prevType = 'boundary';
- } else {
- prevType = 'space';
- }
- i = i + inc;
+ config = $.browser.msie ? config.ie : config.default;
+ config = direction > 0 ? config.right : config.left;
do {
if ( data[i].type !== undefined ) {
break;
} else {
- nextChar = typeof data[i] === 'string' ?
data[i] : data[i][0];
- if ( !pattern.test( nextChar ) ) {
- nextType = 'text';
- } else if ( nextChar !== ' ' ) {
+ oneChar = typeof data[i] === 'string' ? data[i]
: data[i][0];
+ if ( oneChar === ' ' ) {
+ nextType = 'space';
+ } else if ( pattern.test( oneChar ) ) {
nextType = 'boundary';
} else {
- nextType = 'space';
+ nextType = 'text';
}
- if ( prevType !== nextType ) {
+ if ( prevType && prevType !== nextType ) {
if ( config[prevType] && nextType in
config[prevType] ) {
prevType = nextType;
continue;
@@ -130,6 +119,7 @@
break;
}
}
+ prevType = nextType;
}
} while ( data[i += inc] );
return i + ( inc > 0 ? 0 : 1 );
--
To view, visit https://gerrit.wikimedia.org/r/55488
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I7f504f741b4d90201e40bbc40ae2e88fe0db2e33
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Inez <[email protected]>
Gerrit-Reviewer: Christian <[email protected]>
Gerrit-Reviewer: Trevor Parscal <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits