| 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 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 /* patch */ void clear() { | 95 /* patch */ void clear() { |
| 96 _parts = null; | 96 _parts = null; |
| 97 _partsCodeUnits = _bufferPosition = _bufferCodeUnitMagnitude = 0; | 97 _partsCodeUnits = _bufferPosition = _bufferCodeUnitMagnitude = 0; |
| 98 } | 98 } |
| 99 | 99 |
| 100 /** Returns the contents of buffer as a string. */ | 100 /** Returns the contents of buffer as a string. */ |
| 101 /* patch */ String toString() { | 101 /* patch */ String toString() { |
| 102 _consumeBuffer(); | 102 _consumeBuffer(); |
| 103 return (_partsCodeUnits == 0) ? | 103 return (_partsCodeUnits == 0) ? |
| 104 "" : | 104 "" : |
| 105 _StringBase._concatAllNative(_parts, 0, _parts.length); | 105 _StringBase._concatRange(_parts, 0, _parts.length); |
| 106 } | 106 } |
| 107 | 107 |
| 108 /** Ensures that the buffer has enough capacity to add n code units. */ | 108 /** Ensures that the buffer has enough capacity to add n code units. */ |
| 109 void _ensureCapacity(int n) { | 109 void _ensureCapacity(int n) { |
| 110 if (_buffer == null) { | 110 if (_buffer == null) { |
| 111 _buffer = new Uint16List(_BUFFER_SIZE); | 111 _buffer = new Uint16List(_BUFFER_SIZE); |
| 112 } else if (_bufferPosition + n > _buffer.length) { | 112 } else if (_bufferPosition + n > _buffer.length) { |
| 113 _consumeBuffer(); | 113 _consumeBuffer(); |
| 114 } | 114 } |
| 115 } | 115 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 | 149 |
| 150 /** | 150 /** |
| 151 * Compacts the last N parts if their average size allows us to save a | 151 * Compacts the last N parts if their average size allows us to save a |
| 152 * lot of memory by turning them all into a single part. | 152 * lot of memory by turning them all into a single part. |
| 153 */ | 153 */ |
| 154 void _compact() { | 154 void _compact() { |
| 155 if (_partsCodeUnitsSinceCompaction < _PARTS_TO_COMPACT_SIZE_LIMIT) { | 155 if (_partsCodeUnitsSinceCompaction < _PARTS_TO_COMPACT_SIZE_LIMIT) { |
| 156 String compacted = _StringBase._concatAllNative( | 156 String compacted = _StringBase._concatRange( |
| 157 _parts, | 157 _parts, |
| 158 _partsCompactionIndex, // Start | 158 _partsCompactionIndex, // Start |
| 159 _partsCompactionIndex + _PARTS_TO_COMPACT // End | 159 _partsCompactionIndex + _PARTS_TO_COMPACT // End |
| 160 ); | 160 ); |
| 161 _parts.length = _parts.length - _PARTS_TO_COMPACT; | 161 _parts.length = _parts.length - _PARTS_TO_COMPACT; |
| 162 _parts.add(compacted); | 162 _parts.add(compacted); |
| 163 } | 163 } |
| 164 _partsCodeUnitsSinceCompaction = 0; | 164 _partsCodeUnitsSinceCompaction = 0; |
| 165 _partsCompactionIndex = _parts.length; | 165 _partsCompactionIndex = _parts.length; |
| 166 } | 166 } |
| 167 | 167 |
| 168 /** | 168 /** |
| 169 * Create a [String] from the UFT-16 code units in buffer. | 169 * Create a [String] from the UFT-16 code units in buffer. |
| 170 */ | 170 */ |
| 171 static String _create(Uint16List buffer, int length, bool isLatin1) | 171 static String _create(Uint16List buffer, int length, bool isLatin1) |
| 172 native "StringBuffer_createStringFromUint16Array"; | 172 native "StringBuffer_createStringFromUint16Array"; |
| 173 } | 173 } |
| OLD | NEW |