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

Unified Diff: runtime/vm/object.cc

Issue 12315117: Improve performance of Onebytestring allocation and hascode computatio. About 10% improvement on a … (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
===================================================================
--- runtime/vm/object.cc (revision 19062)
+++ runtime/vm/object.cc (working copy)
@@ -10499,9 +10499,15 @@
ASSERT(len >= 0);
ASSERT((begin_index + len) <= str.Length());
StringHasher hasher;
- CodePointIterator it(str, begin_index, len);
- while (it.Next()) {
- hasher.Add(it.Current());
+ if (str.IsOneByteString()) {
+ for (intptr_t i = 0; i < len; i++) {
+ hasher.Add(*OneByteString::CharAddr(str, i + begin_index));
+ }
+ } else {
+ CodePointIterator it(str, begin_index, len);
+ while (it.Next()) {
+ hasher.Add(it.Current());
+ }
}
return hasher.Finalize(String::kHashBits);
}
@@ -11347,17 +11353,16 @@
// This should be caught before we reach here.
FATAL1("Fatal error in OneByteString::New: invalid len %"Pd"\n", len);
}
- String& result = String::Handle();
{
RawObject* raw = Object::Allocate(OneByteString::kClassId,
OneByteString::InstanceSize(len),
space);
NoGCScope no_gc;
- result ^= raw;
- result.SetLength(len);
- result.SetHash(0);
+ RawOneByteString* result = reinterpret_cast<RawOneByteString*>(raw);
+ result->ptr()->length_ = Smi::New(len);
+ result->ptr()->hash_ = 0;
+ return result;
}
- return OneByteString::raw(result);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698