Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 part of dart2js; | 5 part of dart2js; |
| 6 | 6 |
| 7 class CodeBuffer implements StringBuffer { | 7 class CodeBuffer implements StringBuffer { |
| 8 StringBuffer buffer; | 8 |
| 9 List<CodeBufferMarker> markers; | 9 StringBuffer buffer = new StringBuffer(); |
| 10 List<CodeBufferMarker> markers = new List<CodeBufferMarker>(); | |
| 11 | |
| 10 int lastBufferOffset = 0; | 12 int lastBufferOffset = 0; |
| 11 int mappedRangeCounter = 0; | 13 int mappedRangeCounter = 0; |
| 12 | 14 |
| 13 CodeBuffer() | 15 CodeBuffer(); |
|
Lasse Reichstein Nielsen
2013/09/20 11:40:17
You can even remove the constructor entirely.
Prob
| |
| 14 : buffer = new StringBuffer(), | |
| 15 markers = new List<CodeBufferMarker>(); | |
| 16 | 16 |
| 17 int get length => buffer.length; | 17 int get length => buffer.length; |
| 18 | 18 bool get isEmpty => buffer.isEmpty; |
| 19 bool get isEmpty { | 19 bool get isNotEmpty => buffer.isNotEmpty; |
| 20 return buffer.isEmpty; | |
| 21 } | |
| 22 | |
| 23 bool get isNotEmpty => !isEmpty; | |
| 24 | 20 |
| 25 CodeBuffer add(var object) { | 21 CodeBuffer add(var object) { |
| 26 write(object); | 22 write(object); |
| 27 return this; | 23 return this; |
| 28 } | 24 } |
| 29 /** | 25 /** |
| 30 * Converts [object] to a string and adds it to the buffer. If [object] is a | 26 * Converts [object] to a string and adds it to the buffer. If [object] is a |
| 31 * [CodeBuffer], adds its markers to [markers]. | 27 * [CodeBuffer], adds its markers to [markers]. |
| 32 */ | 28 */ |
| 33 CodeBuffer write(var object) { | 29 CodeBuffer write(var object) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 } | 70 } |
| 75 buffer.write(other.getText()); | 71 buffer.write(other.getText()); |
| 76 return this; | 72 return this; |
| 77 } | 73 } |
| 78 | 74 |
| 79 CodeBuffer addAll(Iterable<Object> iterable) => writeAll(iterable); | 75 CodeBuffer addAll(Iterable<Object> iterable) => writeAll(iterable); |
| 80 | 76 |
| 81 CodeBuffer addCharCode(int charCode) => writeCharCode(charCode); | 77 CodeBuffer addCharCode(int charCode) => writeCharCode(charCode); |
| 82 | 78 |
| 83 CodeBuffer writeCharCode(int charCode) { | 79 CodeBuffer writeCharCode(int charCode) { |
| 84 return write(new String.fromCharCodes([charCode])); | 80 buffer.writeCharCode(charCode); |
|
Lasse Reichstein Nielsen
2013/09/20 11:40:17
Ouch. How much would you gain from just this chang
| |
| 81 return this; | |
| 85 } | 82 } |
| 86 | 83 |
| 87 CodeBuffer clear() { | 84 CodeBuffer clear() { |
| 88 buffer = new StringBuffer(); | 85 buffer = new StringBuffer(); |
|
Lasse Reichstein Nielsen
2013/09/20 11:40:17
Per my earlier comments, this is probably a good t
| |
| 89 markers.clear(); | 86 markers.clear(); |
| 90 lastBufferOffset = 0; | 87 lastBufferOffset = 0; |
| 91 return this; | 88 return this; |
| 92 } | 89 } |
| 93 | 90 |
| 94 String toString() { | 91 String toString() { |
| 95 throw "Don't use CodeBuffer.toString() since it drops sourcemap data."; | 92 throw "Don't use CodeBuffer.toString() since it drops sourcemap data."; |
| 96 } | 93 } |
| 97 | 94 |
| 98 String getText() { | 95 String getText() { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 122 }); | 119 }); |
| 123 } | 120 } |
| 124 } | 121 } |
| 125 | 122 |
| 126 class CodeBufferMarker { | 123 class CodeBufferMarker { |
| 127 final int offsetDelta; | 124 final int offsetDelta; |
| 128 final sourcePosition; | 125 final sourcePosition; |
| 129 | 126 |
| 130 CodeBufferMarker(this.offsetDelta, this.sourcePosition); | 127 CodeBufferMarker(this.offsetDelta, this.sourcePosition); |
| 131 } | 128 } |
| OLD | NEW |