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

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

Issue 12300012: Revert "Add StringSink and update StringBuffer." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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/implementation/code_buffer.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 /* abstract */ class StringBuffer {
6 /* patch */ factory StringBuffer([Object content = ""])
7 => new _StringBufferImpl(content);
8 }
9
10 class _StringBufferImpl implements StringBuffer {
11
6 List<String> _buffer; 12 List<String> _buffer;
7 int _length; 13 int _length;
8 14
9 /// Creates the string buffer with an initial content. 15 /// Creates the string buffer with an initial content.
10 /* patch */ StringBuffer([Object content = ""]) { 16 _StringBufferImpl(Object content) {
11 _buffer = new List<String>(); 17 clear();
12 _length = 0; 18 add(content);
13 write(content);
14 } 19 }
15 20
16 /* patch */ int get length => _length; 21 /// Returns the length of the buffer.
22 int get length => _length;
23
24 bool get isEmpty => _length == 0;
17 25
18 /// Adds [obj] to the buffer. 26 /// Adds [obj] to the buffer.
19 /* patch */ void write(Object obj) { 27 void add(Object obj) {
20 // TODO(srdjan): The following four lines could be replaced by 28 // TODO(srdjan): The following four lines could be replaced by
21 // '$obj', but apparently this is too slow on the Dart VM. 29 // '$obj', but apparently this is too slow on the Dart VM.
22 String str; 30 String str = obj.toString();
23 if (obj is String) { 31 if (str is !String) {
24 str = obj; 32 throw new ArgumentError('toString() did not return a string');
25 } else {
26 str = obj.toString();
27 if (str is! String) {
28 throw new ArgumentError('toString() did not return a string');
29 }
30 } 33 }
31 if (str.isEmpty) return; 34 if (str.isEmpty) return;
32 _buffer.add(str); 35 _buffer.add(str);
33 _length += str.length; 36 _length += str.length;
34 } 37 }
35 38
39 /// Adds all items in [objects] to the buffer.
40 void addAll(Iterable objects) {
41 for (Object obj in objects) add(obj);
42 }
43
44 /// Adds the string representation of [charCode] to the buffer.
45 void addCharCode(int charCode) {
46 add(new String.fromCharCodes([charCode]));
47 }
48
36 /// Clears the string buffer. 49 /// Clears the string buffer.
37 /* patch */ void clear() { 50 void clear() {
38 _buffer = new List<String>(); 51 _buffer = new List<String>();
39 _length = 0; 52 _length = 0;
40 } 53 }
41 54
42 /// Returns the contents of buffer as a concatenated string. 55 /// Returns the contents of buffer as a concatenated string.
43 /* patch */ String toString() { 56 String toString() {
44 if (_buffer.length == 0) return ""; 57 if (_buffer.length == 0) return "";
45 if (_buffer.length == 1) return _buffer[0]; 58 if (_buffer.length == 1) return _buffer[0];
46 String result = Strings.concatAll(_buffer); 59 String result = Strings.concatAll(_buffer);
47 _buffer.clear(); 60 _buffer.clear();
48 _buffer.add(result); 61 _buffer.add(result);
49 // Since we track the length at each add operation, there is no 62 // Since we track the length at each add operation, there is no
50 // need to update it in this function. 63 // need to update it in this function.
51 return result; 64 return result;
52 } 65 }
53 } 66 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/code_buffer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698