Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: runtime/lib/string_patch.dart

Issue 25087006: Improve performance of string buffer by modifying concatAll native to allow growable array and an i… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/lib/string_buffer_patch.dart ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 patch class String { 5 patch class String {
6 /* patch */ factory String.fromCharCodes(Iterable<int> charCodes) { 6 /* patch */ factory String.fromCharCodes(Iterable<int> charCodes) {
7 return _StringBase.createFromCharCodes(charCodes); 7 return _StringBase.createFromCharCodes(charCodes);
8 } 8 }
9 } 9 }
10 10
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 } 388 }
389 buffer.write(onNonMatch(this.substring(startIndex))); 389 buffer.write(onNonMatch(this.substring(startIndex)));
390 return buffer.toString(); 390 return buffer.toString();
391 } 391 }
392 392
393 393
394 /** 394 /**
395 * Convert all objects in [values] to strings and concat them 395 * Convert all objects in [values] to strings and concat them
396 * into a result string. 396 * into a result string.
397 */ 397 */
398 static String _interpolate(List values) { 398 static String _interpolate(List<String> values) {
399 final int numValues = values.length; 399 final int numValues = values.length;
400 _ObjectArray stringList = new List(numValues); 400 _ObjectArray stringList = new List<String>(numValues);
401 bool isOneByteString = true; 401 bool isOneByteString = true;
402 int totalLength = 0; 402 int totalLength = 0;
403 for (int i = 0; i < numValues; i++) { 403 for (int i = 0; i < numValues; i++) {
404 var s = values[i].toString(); 404 var s = values[i].toString();
405 if (isOneByteString && (s._cid == _OneByteString._classId)) { 405 if (isOneByteString && (s._cid == _OneByteString._classId)) {
406 totalLength += s.length; 406 totalLength += s.length;
407 } else { 407 } else {
408 isOneByteString = false; 408 isOneByteString = false;
409 } 409 }
410 stringList[i] = s; 410 stringList[i] = s;
411 } 411 }
412 if (isOneByteString) { 412 if (isOneByteString) {
413 return _OneByteString._concatAll(stringList, totalLength); 413 return _OneByteString._concatAll(stringList, totalLength);
414 } 414 }
415 return _concatAllNative(stringList); 415 return _concatAllNative(stringList, 0, stringList.length);
416 } 416 }
417 417
418 Iterable<Match> allMatches(String str) { 418 Iterable<Match> allMatches(String str) {
419 List<Match> result = new List<Match>(); 419 List<Match> result = new List<Match>();
420 int length = str.length; 420 int length = str.length;
421 int patternLength = this.length; 421 int patternLength = this.length;
422 int startIndex = 0; 422 int startIndex = 0;
423 while (true) { 423 while (true) {
424 int position = str.indexOf(this, startIndex); 424 int position = str.indexOf(this, startIndex);
425 if (position == -1) { 425 if (position == -1) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 } 490 }
491 491
492 List<int> get codeUnits => new _CodeUnits(this); 492 List<int> get codeUnits => new _CodeUnits(this);
493 493
494 Runes get runes => new Runes(this); 494 Runes get runes => new Runes(this);
495 495
496 String toUpperCase() native "String_toUpperCase"; 496 String toUpperCase() native "String_toUpperCase";
497 497
498 String toLowerCase() native "String_toLowerCase"; 498 String toLowerCase() native "String_toLowerCase";
499 499
500 // Call this method if not all list elements are OneByteString-s. 500 // Call this method if not all list elements are known to be OneByteString(s).
501 static String _concatAllNative(_ObjectArray<String> strings) 501 // 'strings' must be an _ObjectArray or _GrowableObjectArray.
502 static String _concatAllNative(List<String> strings, int start, int end)
502 native "Strings_concatAll"; 503 native "Strings_concatAll";
503 } 504 }
504 505
505 506
506 class _OneByteString extends _StringBase implements String { 507 class _OneByteString extends _StringBase implements String {
507 static final int _classId = "A"._cid; 508 static final int _classId = "A"._cid;
508 509
509 factory _OneByteString._uninstantiable() { 510 factory _OneByteString._uninstantiable() {
510 throw new UnsupportedError( 511 throw new UnsupportedError(
511 "_OneByteString can only be allocated by the VM"); 512 "_OneByteString can only be allocated by the VM");
(...skipping 16 matching lines...) Expand all
528 return _splitWithCharCode(pattern.codeUnitAt(0)); 529 return _splitWithCharCode(pattern.codeUnitAt(0));
529 } 530 }
530 return super.split(pattern); 531 return super.split(pattern);
531 } 532 }
532 533
533 // All element of 'strings' must be OneByteStrings. 534 // All element of 'strings' must be OneByteStrings.
534 static _concatAll(_ObjectArray<String> strings, int totalLength) { 535 static _concatAll(_ObjectArray<String> strings, int totalLength) {
535 // TODO(srdjan): Improve code below and raise or eliminate the limit. 536 // TODO(srdjan): Improve code below and raise or eliminate the limit.
536 if (totalLength > 128) { 537 if (totalLength > 128) {
537 // Native is quicker. 538 // Native is quicker.
538 return _StringBase._concatAllNative(strings); 539 return _StringBase._concatAllNative(strings, 0, strings.length);
539 } 540 }
540 var res = _OneByteString._allocate(totalLength); 541 var res = _OneByteString._allocate(totalLength);
541 final stringsLength = strings.length; 542 final stringsLength = strings.length;
542 int rIx = 0; 543 int rIx = 0;
543 for (int i = 0; i < stringsLength; i++) { 544 for (int i = 0; i < stringsLength; i++) {
544 _OneByteString e = strings[i]; 545 _OneByteString e = strings[i];
545 final eLength = e.length; 546 final eLength = e.length;
546 for (int s = 0; s < eLength; s++) { 547 for (int s = 0; s < eLength; s++) {
547 res._setAt(rIx++, e.codeUnitAt(s)); 548 res._setAt(rIx++, e.codeUnitAt(s));
548 } 549 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 class _CodeUnits extends Object with ListMixin<int>, 635 class _CodeUnits extends Object with ListMixin<int>,
635 UnmodifiableListMixin<int> { 636 UnmodifiableListMixin<int> {
636 /** The string that this is the code units of. */ 637 /** The string that this is the code units of. */
637 String _string; 638 String _string;
638 639
639 _CodeUnits(this._string); 640 _CodeUnits(this._string);
640 641
641 int get length => _string.length; 642 int get length => _string.length;
642 int operator[](int i) => _string.codeUnitAt(i); 643 int operator[](int i) => _string.codeUnitAt(i);
643 } 644 }
OLDNEW
« no previous file with comments | « runtime/lib/string_buffer_patch.dart ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698