| 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 141   /** | 141   /** | 
| 142    * Adds a new part to this string buffer and keeps track of how | 142    * Adds a new part to this string buffer and keeps track of how | 
| 143    * many code units are contained in the parts. | 143    * many code units are contained in the parts. | 
| 144    */ | 144    */ | 
| 145   void _addPart(String str) { | 145   void _addPart(String str) { | 
| 146     int length = str.length; | 146     int length = str.length; | 
| 147     _partsCodeUnits += length; | 147     _partsCodeUnits += length; | 
| 148     _partsCodeUnitsSinceCompaction += length; | 148     _partsCodeUnitsSinceCompaction += length; | 
| 149 | 149 | 
| 150     if (_parts == null) { | 150     if (_parts == null) { | 
| 151       _parts = [ str ]; | 151       // Empirically this is a good capacity to minimize total bytes allocated. | 
|  | 152       _parts = new _GrowableList.withCapacity(10)..add(str); | 
| 152     } else { | 153     } else { | 
| 153       _parts.add(str); | 154       _parts.add(str); | 
| 154       int partsSinceCompaction = _parts.length - _partsCompactionIndex; | 155       int partsSinceCompaction = _parts.length - _partsCompactionIndex; | 
| 155       if (partsSinceCompaction == _PARTS_TO_COMPACT) { | 156       if (partsSinceCompaction == _PARTS_TO_COMPACT) { | 
| 156         _compact(); | 157         _compact(); | 
| 157       } | 158       } | 
| 158     } | 159     } | 
| 159   } | 160   } | 
| 160 | 161 | 
| 161   /** | 162   /** | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
| 175     _partsCodeUnitsSinceCompaction = 0; | 176     _partsCodeUnitsSinceCompaction = 0; | 
| 176     _partsCompactionIndex = _parts.length; | 177     _partsCompactionIndex = _parts.length; | 
| 177   } | 178   } | 
| 178 | 179 | 
| 179   /** | 180   /** | 
| 180    * Create a [String] from the UFT-16 code units in buffer. | 181    * Create a [String] from the UFT-16 code units in buffer. | 
| 181    */ | 182    */ | 
| 182   static String _create(Uint16List buffer, int length, bool isLatin1) | 183   static String _create(Uint16List buffer, int length, bool isLatin1) | 
| 183       native "StringBuffer_createStringFromUint16Array"; | 184       native "StringBuffer_createStringFromUint16Array"; | 
| 184 } | 185 } | 
| OLD | NEW | 
|---|