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

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

Issue 1086043002: dart2js implementation of StringBuffer.writeAll that optimizes better (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: use Duration instead of StringBuffer for pub tests... until we optimize that! Created 5 years, 8 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 | « no previous file | sdk/lib/_internal/compiler/js_lib/core_patch.dart » ('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 StringBuffer { 5 patch class StringBuffer {
6 static const int _BUFFER_SIZE = 64; 6 static const int _BUFFER_SIZE = 64;
7 static const int _PARTS_TO_COMPACT = 128; 7 static const int _PARTS_TO_COMPACT = 128;
8 static const int _PARTS_TO_COMPACT_SIZE_LIMIT = _PARTS_TO_COMPACT * 8; 8 static const int _PARTS_TO_COMPACT_SIZE_LIMIT = _PARTS_TO_COMPACT * 8;
9 9
10 /** 10 /**
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 throw new RangeError.range(charCode, 0, 0x10FFFF); 84 throw new RangeError.range(charCode, 0, 0x10FFFF);
85 } 85 }
86 _ensureCapacity(2); 86 _ensureCapacity(2);
87 int bits = charCode - 0x10000; 87 int bits = charCode - 0x10000;
88 _buffer[_bufferPosition++] = 0xD800 | (bits >> 10); 88 _buffer[_bufferPosition++] = 0xD800 | (bits >> 10);
89 _buffer[_bufferPosition++] = 0xDC00 | (bits & 0x3FF); 89 _buffer[_bufferPosition++] = 0xDC00 | (bits & 0x3FF);
90 _bufferCodeUnitMagnitude |= 0xFFFF; 90 _bufferCodeUnitMagnitude |= 0xFFFF;
91 } 91 }
92 } 92 }
93 93
94 /* patch */ void writeAll(Iterable objects, [String separator = ""]) {
95 Iterator iterator = objects.iterator;
96 if (!iterator.moveNext()) return;
97 if (separator.isEmpty) {
98 do {
99 write(iterator.current);
100 } while (iterator.moveNext());
101 } else {
102 write(iterator.current);
103 while (iterator.moveNext()) {
104 write(separator);
105 write(iterator.current);
106 }
107 }
108 }
109
110 /* patch */ void writeln([Object obj = ""]) {
111 write(obj);
112 write("\n");
113 }
114
94 /** Makes the buffer empty. */ 115 /** Makes the buffer empty. */
95 /* patch */ void clear() { 116 /* patch */ void clear() {
96 _parts = null; 117 _parts = null;
97 _partsCodeUnits = _bufferPosition = _bufferCodeUnitMagnitude = 0; 118 _partsCodeUnits = _bufferPosition = _bufferCodeUnitMagnitude = 0;
98 } 119 }
99 120
100 /** Returns the contents of buffer as a string. */ 121 /** Returns the contents of buffer as a string. */
101 /* patch */ String toString() { 122 /* patch */ String toString() {
102 _consumeBuffer(); 123 _consumeBuffer();
103 return (_partsCodeUnits == 0) ? 124 return (_partsCodeUnits == 0) ?
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 _partsCodeUnitsSinceCompaction = 0; 185 _partsCodeUnitsSinceCompaction = 0;
165 _partsCompactionIndex = _parts.length; 186 _partsCompactionIndex = _parts.length;
166 } 187 }
167 188
168 /** 189 /**
169 * Create a [String] from the UFT-16 code units in buffer. 190 * Create a [String] from the UFT-16 code units in buffer.
170 */ 191 */
171 static String _create(Uint16List buffer, int length, bool isLatin1) 192 static String _create(Uint16List buffer, int length, bool isLatin1)
172 native "StringBuffer_createStringFromUint16Array"; 193 native "StringBuffer_createStringFromUint16Array";
173 } 194 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/js_lib/core_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698