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

Unified Diff: dart/sdk/lib/core/string_buffer.dart

Issue 11565034: Improve performance of dart2js StringBuffer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Updated to lib_v2 and private libraries. Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: dart/sdk/lib/core/string_buffer.dart
diff --git a/dart/sdk/lib/core/string_buffer.dart b/dart/sdk/lib/core/string_buffer.dart
index 71bf31d2a0066e8590d2d7f8182061be9a2a367a..d8b393583952238a7e66027ba20d0b45b86179e4 100644
--- a/dart/sdk/lib/core/string_buffer.dart
+++ b/dart/sdk/lib/core/string_buffer.dart
@@ -12,7 +12,7 @@ part of dart.core;
abstract class StringBuffer {
/// Creates the string buffer with an initial content.
- factory StringBuffer([Object content = ""]) => new _StringBufferImpl(content);
+ external factory StringBuffer([Object content = ""]);
/// Returns the length of the buffer.
int get length;
@@ -35,61 +35,3 @@ abstract class StringBuffer {
/// Returns the contents of buffer as a concatenated string.
String toString();
}
-
-class _StringBufferImpl implements StringBuffer {
-
- List<String> _buffer;
- int _length;
-
- /// Creates the string buffer with an initial content.
- _StringBufferImpl(Object content) {
- clear();
- add(content);
- }
-
- /// Returns the length of the buffer.
- int get length => _length;
-
- bool get isEmpty => _length == 0;
-
- /// Adds [obj] to the buffer.
- void add(Object obj) {
- // TODO(srdjan): The following four lines could be replaced by
- // '$obj', but apparently this is too slow on the Dart VM.
- String str = obj.toString();
- if (str is !String) {
- throw new ArgumentError('toString() did not return a string');
- }
- if (str.isEmpty) return;
- _buffer.add(str);
- _length += str.length;
- }
-
- /// Adds all items in [objects] to the buffer.
- void addAll(Iterable objects) {
- for (Object obj in objects) add(obj);
- }
-
- /// Adds the string representation of [charCode] to the buffer.
- void addCharCode(int charCode) {
- add(new String.fromCharCodes([charCode]));
- }
-
- /// Clears the string buffer.
- void clear() {
- _buffer = new List<String>();
- _length = 0;
- }
-
- /// Returns the contents of buffer as a concatenated string.
- String toString() {
- if (_buffer.length == 0) return "";
- if (_buffer.length == 1) return _buffer[0];
- String result = Strings.concatAll(_buffer);
- _buffer.clear();
- _buffer.add(result);
- // Since we track the length at each add operation, there is no
- // need to update it in this function.
- return result;
- }
-}

Powered by Google App Engine
This is Rietveld 408576698