Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 part of dart.core; | 5 part of dart.core; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * The StringBuffer class is useful for concatenating strings | 8 * The StringBuffer class is useful for concatenating strings |
| 9 * efficiently. Only on a call to [toString] are the strings | 9 * efficiently. Only on a call to [toString] are the strings |
| 10 * concatenated to a single String. | 10 * concatenated to a single String. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 add(content); | 47 add(content); |
| 48 } | 48 } |
| 49 | 49 |
| 50 /// Returns the length of the buffer. | 50 /// Returns the length of the buffer. |
| 51 int get length => _length; | 51 int get length => _length; |
| 52 | 52 |
| 53 bool get isEmpty => _length == 0; | 53 bool get isEmpty => _length == 0; |
| 54 | 54 |
| 55 /// Adds [obj] to the buffer. | 55 /// Adds [obj] to the buffer. |
| 56 void add(Object obj) { | 56 void add(Object obj) { |
| 57 String str = obj.toString(); | 57 String str = '$obj'; |
|
srdjan
2012/12/20 16:40:29
For the VM, string interpolation is slower than ca
Ivan Posva
2012/12/20 16:42:41
I do not see the purpose of this change. Please ex
ahe
2012/12/20 17:10:37
The purpose of this change is to get sane semantic
sra1
2012/12/20 19:07:41
obj.toString() should almost never be called expli
ahe
2012/12/21 11:23:38
I have changed the code to use an explicit check a
| |
| 58 if (str == null || str.isEmpty) return; | 58 if (str.isEmpty) return; |
| 59 _buffer.add(str); | 59 _buffer.add(str); |
| 60 _length += str.length; | 60 _length += str.length; |
| 61 } | 61 } |
| 62 | 62 |
| 63 /// Adds all items in [objects] to the buffer. | 63 /// Adds all items in [objects] to the buffer. |
| 64 void addAll(Collection objects) { | 64 void addAll(Collection objects) { |
| 65 for (Object obj in objects) add(obj); | 65 for (Object obj in objects) add(obj); |
| 66 } | 66 } |
| 67 | 67 |
| 68 /// Adds the string representation of [charCode] to the buffer. | 68 /// Adds the string representation of [charCode] to the buffer. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 81 if (_buffer.length == 0) return ""; | 81 if (_buffer.length == 0) return ""; |
| 82 if (_buffer.length == 1) return _buffer[0]; | 82 if (_buffer.length == 1) return _buffer[0]; |
| 83 String result = Strings.concatAll(_buffer); | 83 String result = Strings.concatAll(_buffer); |
| 84 _buffer.clear(); | 84 _buffer.clear(); |
| 85 _buffer.add(result); | 85 _buffer.add(result); |
| 86 // Since we track the length at each add operation, there is no | 86 // Since we track the length at each add operation, there is no |
| 87 // need to update it in this function. | 87 // need to update it in this function. |
| 88 return result; | 88 return result; |
| 89 } | 89 } |
| 90 } | 90 } |
| OLD | NEW |