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

Unified Diff: runtime/lib/string.cc

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
« no previous file with comments | « no previous file | runtime/lib/string_buffer_patch.dart » ('j') | runtime/lib/string_patch.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/string.cc
===================================================================
--- runtime/lib/string.cc (revision 28056)
+++ runtime/lib/string.cc (working copy)
@@ -214,12 +214,44 @@
}
-DEFINE_NATIVE_ENTRY(Strings_concatAll, 1) {
- GET_NON_NULL_NATIVE_ARGUMENT(Array, strings, arguments->NativeArgAt(0));
- ASSERT(!strings.IsNull());
+DEFINE_NATIVE_ENTRY(Strings_concatAll, 3) {
+ GET_NON_NULL_NATIVE_ARGUMENT(Instance, argument, arguments->NativeArgAt(0));
+ GET_NON_NULL_NATIVE_ARGUMENT(Smi, start, arguments->NativeArgAt(1));
+ GET_NON_NULL_NATIVE_ARGUMENT(Smi, end, arguments->NativeArgAt(2));
+ const intptr_t start_ix = start.Value();
+ const intptr_t end_ix = end.Value();
+ if (start_ix < 0) {
+ const Array& args = Array::Handle(Array::New(1));
+ args.SetAt(0, start);
+ Exceptions::ThrowByType(Exceptions::kArgument, args);
+ }
+ Array& strings = Array::Handle();
+ if (argument.IsArray()) {
+ strings ^= argument.raw();
+ if (end_ix > strings.Length()) {
+ const Array& args = Array::Handle(Array::New(1));
+ args.SetAt(0, end);
+ Exceptions::ThrowByType(Exceptions::kArgument, args);
sra1 2013/09/30 17:54:43 This is such a common sequence I am surprised it i
srdjan 2013/10/01 14:57:44 Will do that in next CL.
+ }
+ } else if (argument.IsGrowableObjectArray()) {
+ // Allocate new array and copy data into it.
sra1 2013/09/30 17:54:43 Comment is wrong - you don't copy the the array. Y
srdjan 2013/10/01 14:57:44 Removed comment.
+ GrowableObjectArray& g = GrowableObjectArray::Handle();
+ g ^= argument.raw();
siva 2013/09/30 18:27:21 'g' seems like a cryptic name, why not strings =
srdjan 2013/10/01 14:57:44 strings is the backing store array whose length is
+ strings = g.data();
+ if (end_ix > g.Length()) {
+ const Array& args = Array::Handle(Array::New(1));
+ args.SetAt(0, end);
+ Exceptions::ThrowByType(Exceptions::kArgument, args);
+ }
+ } else {
+ const Array& args = Array::Handle(Array::New(1));
+ args.SetAt(0, argument);
+ Exceptions::ThrowByType(Exceptions::kArgument, args);
+ }
siva 2013/09/30 18:27:21 The if (end_ix > length) { .... .... } blob ca
srdjan 2013/10/01 14:57:44 Yes.
+#if defined(DEBUG)
// Check that the array contains strings.
Instance& elem = Instance::Handle();
- for (intptr_t i = 0; i < strings.Length(); i++) {
+ for (intptr_t i = start_ix; i < end_ix; i++) {
elem ^= strings.At(i);
if (!elem.IsString()) {
const Array& args = Array::Handle(Array::New(1));
@@ -227,7 +259,8 @@
Exceptions::ThrowByType(Exceptions::kArgument, args);
}
}
- return String::ConcatAll(strings);
+#endif
siva 2013/09/30 18:27:21 Why does this check have to be done in DEBUG mode?
srdjan 2013/10/01 14:57:44 Changing to ASSERT.
+ return String::ConcatAllRange(strings, start_ix, end_ix, Heap::kNew);
}
« no previous file with comments | « no previous file | runtime/lib/string_buffer_patch.dart » ('j') | runtime/lib/string_patch.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698