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

Unified Diff: runtime/lib/string_buffer_patch.dart

Issue 25087006: Improve performance of string buffer by modifying concatAll native to allow growable array and an i… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: runtime/lib/string_buffer_patch.dart
===================================================================
--- runtime/lib/string_buffer_patch.dart (revision 28056)
+++ runtime/lib/string_buffer_patch.dart (working copy)
@@ -11,7 +11,7 @@
* When strings are written to the string buffer, we add them to a
* list of string parts.
*/
- List _parts = null;
+ List<String> _parts = null;
/**
* Total number of code units in the string parts. Does not include
@@ -28,7 +28,6 @@
*/
int _partsCompactionIndex = 0;
int _partsCodeUnitsSinceCompaction = 0;
- _ObjectArray _partsCompactionArray = null;
/**
* The buffer is used to build up a string from code units. It is
@@ -101,15 +100,9 @@
/** Returns the contents of buffer as a string. */
/* patch */ String toString() {
_consumeBuffer();
- if (_partsCodeUnits == 0) return "";
-
- // TODO(kasperl): It would be nice if concatAllNative would
- // allow me to pass in a grownable array directly, but for
- // now we have to copy the contents to a non-growable array.
- int length = _parts.length;
- _ObjectArray array = new _ObjectArray(length);
- for (int i = 0; i < length; i++) array[i] = _parts[i];
- return _StringBase._concatAllNative(array);
+ return (_partsCodeUnits == 0) ?
+ "" :
+ _StringBase._concatAllNative(_parts, 0, _parts.length);
}
/** Ensures that the buffer has enough capacity to add n code units. */
@@ -160,18 +153,13 @@
*/
void _compact() {
if (_partsCodeUnitsSinceCompaction < _PARTS_TO_COMPACT_SIZE_LIMIT) {
- if (_partsCompactionArray == null) {
- _partsCompactionArray = new _ObjectArray(_PARTS_TO_COMPACT);
- }
- for (int i = 0; i < _PARTS_TO_COMPACT; i++) {
- _partsCompactionArray[i] = _parts[i + _partsCompactionIndex];
- }
- String compacted = _StringBase._concatAllNative(_partsCompactionArray);
+ String compacted = _StringBase._concatAllNative(
+ _parts,
+ _partsCompactionIndex, // Start
+ _partsCompactionIndex + _PARTS_TO_COMPACT // End
+ );
_parts.length = _parts.length - _PARTS_TO_COMPACT;
_parts.add(compacted);
- for (int i = 0; i < _PARTS_TO_COMPACT; i++) {
- _partsCompactionArray[i] = null;
- }
}
_partsCodeUnitsSinceCompaction = 0;
_partsCompactionIndex = _parts.length;

Powered by Google App Engine
This is Rietveld 408576698