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

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

Issue 25813002: - Rename arrays to lists: (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
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 12 matching lines...) Expand all
23 int get hashCode native "String_getHashCode"; 23 int get hashCode native "String_getHashCode";
24 24
25 /** 25 /**
26 * Create the most efficient string representation for specified 26 * Create the most efficient string representation for specified
27 * [codePoints]. 27 * [codePoints].
28 */ 28 */
29 static String createFromCharCodes(Iterable<int> charCodes) { 29 static String createFromCharCodes(Iterable<int> charCodes) {
30 if (charCodes != null) { 30 if (charCodes != null) {
31 // TODO(srdjan): Also skip copying of typed arrays. 31 // TODO(srdjan): Also skip copying of typed arrays.
32 final ccid = charCodes._cid; 32 final ccid = charCodes._cid;
33 if ((ccid != _ObjectArray._classId) && 33 if ((ccid != _List._classId) &&
34 (ccid != _GrowableObjectArray._classId) && 34 (ccid != _GrowableList._classId) &&
35 (ccid != _ImmutableArray._classId)) { 35 (ccid != _ImmutableList._classId)) {
36 charCodes = new List<int>.from(charCodes, growable: false); 36 charCodes = new List<int>.from(charCodes, growable: false);
37 } 37 }
38 38
39 bool isOneByteString = true; 39 bool isOneByteString = true;
40 for (int i = 0; i < charCodes.length; i++) { 40 for (int i = 0; i < charCodes.length; i++) {
41 int e = charCodes[i]; 41 int e = charCodes[i];
42 if (e is! _Smi) throw new ArgumentError(e); 42 if (e is! _Smi) throw new ArgumentError(e);
43 // Is e Latin1? 43 // Is e Latin1?
44 if ((e < 0) || (e > 0xFF)) { 44 if ((e < 0) || (e > 0xFF)) {
45 isOneByteString = false; 45 isOneByteString = false;
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
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<String> 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<String>(numValues); 400 _List 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 if (s is! String) { 409 if (s is! String) {
410 throw new ArgumentError(s); 410 throw new ArgumentError(s);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 494
495 List<int> get codeUnits => new _CodeUnits(this); 495 List<int> get codeUnits => new _CodeUnits(this);
496 496
497 Runes get runes => new Runes(this); 497 Runes get runes => new Runes(this);
498 498
499 String toUpperCase() native "String_toUpperCase"; 499 String toUpperCase() native "String_toUpperCase";
500 500
501 String toLowerCase() native "String_toLowerCase"; 501 String toLowerCase() native "String_toLowerCase";
502 502
503 // Call this method if not all list elements are known to be OneByteString(s). 503 // Call this method if not all list elements are known to be OneByteString(s).
504 // 'strings' must be an _ObjectArray or _GrowableObjectArray. 504 // 'strings' must be an _List or _GrowableList.
505 static String _concatAllNative(List<String> strings, int start, int end) 505 static String _concatAllNative(List<String> strings, int start, int end)
506 native "Strings_concatAll"; 506 native "Strings_concatAll";
507 } 507 }
508 508
509 509
510 class _OneByteString extends _StringBase implements String { 510 class _OneByteString extends _StringBase implements String {
511 static final int _classId = "A"._cid; 511 static final int _classId = "A"._cid;
512 512
513 factory _OneByteString._uninstantiable() { 513 factory _OneByteString._uninstantiable() {
514 throw new UnsupportedError( 514 throw new UnsupportedError(
(...skipping 13 matching lines...) Expand all
528 native "OneByteString_splitWithCharCode"; 528 native "OneByteString_splitWithCharCode";
529 529
530 List<String> split(Pattern pattern) { 530 List<String> split(Pattern pattern) {
531 if ((pattern._cid == _OneByteString._classId) && (pattern.length == 1)) { 531 if ((pattern._cid == _OneByteString._classId) && (pattern.length == 1)) {
532 return _splitWithCharCode(pattern.codeUnitAt(0)); 532 return _splitWithCharCode(pattern.codeUnitAt(0));
533 } 533 }
534 return super.split(pattern); 534 return super.split(pattern);
535 } 535 }
536 536
537 // All element of 'strings' must be OneByteStrings. 537 // All element of 'strings' must be OneByteStrings.
538 static _concatAll(_ObjectArray<String> strings, int totalLength) { 538 static _concatAll(_List<String> strings, int totalLength) {
539 // TODO(srdjan): Improve code below and raise or eliminate the limit. 539 // TODO(srdjan): Improve code below and raise or eliminate the limit.
540 if (totalLength > 128) { 540 if (totalLength > 128) {
541 // Native is quicker. 541 // Native is quicker.
542 return _StringBase._concatAllNative(strings, 0, strings.length); 542 return _StringBase._concatAllNative(strings, 0, strings.length);
543 } 543 }
544 var res = _OneByteString._allocate(totalLength); 544 var res = _OneByteString._allocate(totalLength);
545 final stringsLength = strings.length; 545 final stringsLength = strings.length;
546 int rIx = 0; 546 int rIx = 0;
547 for (int i = 0; i < stringsLength; i++) { 547 for (int i = 0; i < stringsLength; i++) {
548 _OneByteString e = strings[i]; 548 _OneByteString e = strings[i];
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 class _CodeUnits extends Object with ListMixin<int>, 638 class _CodeUnits extends Object with ListMixin<int>,
639 UnmodifiableListMixin<int> { 639 UnmodifiableListMixin<int> {
640 /** The string that this is the code units of. */ 640 /** The string that this is the code units of. */
641 String _string; 641 String _string;
642 642
643 _CodeUnits(this._string); 643 _CodeUnits(this._string);
644 644
645 int get length => _string.length; 645 int get length => _string.length;
646 int operator[](int i) => _string.codeUnitAt(i); 646 int operator[](int i) => _string.codeUnitAt(i);
647 } 647 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698