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

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

Issue 14868002: Do not copy immutable arrays in String.createFromCharCodes. Tighten the types a little in string_pa… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 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.cc ('k') | no next file » | 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
11 11
12 /** 12 /**
13 * [_StringBase] contains common methods used by concrete String 13 * [_StringBase] contains common methods used by concrete String
14 * implementations, e.g., _OneByteString. 14 * implementations, e.g., _OneByteString.
15 */ 15 */
16 class _StringBase { 16 class _StringBase {
17 17
18 factory _StringBase._uninstantiable() { 18 factory _StringBase._uninstantiable() {
19 throw new UnsupportedError( 19 throw new UnsupportedError(
20 "_StringBase can't be instaniated"); 20 "_StringBase can't be instaniated");
21 } 21 }
22 22
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 is! _ObjectArray && charCodes is! _GrowableObjectArray) { 30 // TODO(srdjan): Also skip copying of typed arrays.
31 if (charCodes is! _ObjectArray &&
Ivan Posva 2013/05/03 15:44:27 This will not work long-term. Especially once we h
srdjan 2013/05/03 16:44:47 Good point. What is the ETA for "implements dynami
32 charCodes is! _GrowableObjectArray &&
33 charCodes is! _ImmutableArray) {
31 charCodes = new List<int>.from(charCodes, growable: false); 34 charCodes = new List<int>.from(charCodes, growable: false);
32 } 35 }
36
33 return _createFromCodePoints(charCodes); 37 return _createFromCodePoints(charCodes);
34 } 38 }
35 39
36 static String _createFromCodePoints(List<int> codePoints) 40 static String _createFromCodePoints(List<int> codePoints)
37 native "StringBase_createFromCodePoints"; 41 native "StringBase_createFromCodePoints";
38 42
39 String operator [](int index) native "String_charAt"; 43 String operator [](int index) native "String_charAt";
40 44
41 int codeUnitAt(int index) native "String_codeUnitAt"; 45 int codeUnitAt(int index) native "String_codeUnitAt";
42 46
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 return buffer.toString(); 311 return buffer.toString();
308 } 312 }
309 313
310 314
311 /** 315 /**
312 * Convert all objects in [values] to strings and concat them 316 * Convert all objects in [values] to strings and concat them
313 * into a result string. 317 * into a result string.
314 */ 318 */
315 static String _interpolate(List values) { 319 static String _interpolate(List values) {
316 int numValues = values.length; 320 int numValues = values.length;
317 var stringList = new List(numValues); 321 _ObjectArray stringList = new List(numValues);
318 for (int i = 0; i < numValues; i++) { 322 for (int i = 0; i < numValues; i++) {
319 stringList[i] = values[i].toString(); 323 stringList[i] = values[i].toString();
320 } 324 }
321 return _concatAll(stringList); 325 return _concatAll(stringList);
322 } 326 }
323 327
324 Iterable<Match> allMatches(String str) { 328 Iterable<Match> allMatches(String str) {
325 List<Match> result = new List<Match>(); 329 List<Match> result = new List<Match>();
326 int length = str.length; 330 int length = str.length;
327 int patternLength = this.length; 331 int patternLength = this.length;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 stringsArray = new _ObjectArray(len); 425 stringsArray = new _ObjectArray(len);
422 int i = 0; 426 int i = 0;
423 for (String string in strings) { 427 for (String string in strings) {
424 if (string is! String) throw new ArgumentError(string); 428 if (string is! String) throw new ArgumentError(string);
425 stringsArray[i++] = string; 429 stringsArray[i++] = string;
426 } 430 }
427 } 431 }
428 return _concatAll(stringsArray); 432 return _concatAll(stringsArray);
429 } 433 }
430 434
431 static String _concatAll(List<String> strings) 435 static String _concatAll(_ObjectArray<String> strings)
432 native "Strings_concatAll"; 436 native "Strings_concatAll";
433 } 437 }
434 438
435 439
436 class _OneByteString extends _StringBase implements String { 440 class _OneByteString extends _StringBase implements String {
437 factory _OneByteString._uninstantiable() { 441 factory _OneByteString._uninstantiable() {
438 throw new UnsupportedError( 442 throw new UnsupportedError(
439 "_OneByteString can only be allocated by the VM"); 443 "_OneByteString can only be allocated by the VM");
440 } 444 }
441 445
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 class _CodeUnits extends Object with ListMixin<int>, 589 class _CodeUnits extends Object with ListMixin<int>,
586 UnmodifiableListMixin<int> { 590 UnmodifiableListMixin<int> {
587 /** The string that this is the code units of. */ 591 /** The string that this is the code units of. */
588 String _string; 592 String _string;
589 593
590 _CodeUnits(this._string); 594 _CodeUnits(this._string);
591 595
592 int get length => _string.length; 596 int get length => _string.length;
593 int operator[](int i) => _string.codeUnitAt(i); 597 int operator[](int i) => _string.codeUnitAt(i);
594 } 598 }
OLDNEW
« no previous file with comments | « runtime/lib/string.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698