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

Side by Side 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, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "vm/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/bigint_operations.h" 10 #include "vm/bigint_operations.h"
(...skipping 10481 matching lines...) Expand 10 before | Expand all | Expand 10 after
10492 private: 10492 private:
10493 uint32_t hash_; 10493 uint32_t hash_;
10494 }; 10494 };
10495 10495
10496 10496
10497 intptr_t String::Hash(const String& str, intptr_t begin_index, intptr_t len) { 10497 intptr_t String::Hash(const String& str, intptr_t begin_index, intptr_t len) {
10498 ASSERT(begin_index >= 0); 10498 ASSERT(begin_index >= 0);
10499 ASSERT(len >= 0); 10499 ASSERT(len >= 0);
10500 ASSERT((begin_index + len) <= str.Length()); 10500 ASSERT((begin_index + len) <= str.Length());
10501 StringHasher hasher; 10501 StringHasher hasher;
10502 CodePointIterator it(str, begin_index, len); 10502 if (str.IsOneByteString()) {
10503 while (it.Next()) { 10503 for (intptr_t i = 0; i < len; i++) {
10504 hasher.Add(it.Current()); 10504 hasher.Add(*OneByteString::CharAddr(str, i + begin_index));
10505 }
10506 } else {
10507 CodePointIterator it(str, begin_index, len);
10508 while (it.Next()) {
10509 hasher.Add(it.Current());
10510 }
10505 } 10511 }
10506 return hasher.Finalize(String::kHashBits); 10512 return hasher.Finalize(String::kHashBits);
10507 } 10513 }
10508 10514
10509 10515
10510 template<typename T> 10516 template<typename T>
10511 static intptr_t HashImpl(const T* characters, intptr_t len) { 10517 static intptr_t HashImpl(const T* characters, intptr_t len) {
10512 ASSERT(len >= 0); 10518 ASSERT(len >= 0);
10513 StringHasher hasher; 10519 StringHasher hasher;
10514 for (intptr_t i = 0; i < len; i++) { 10520 for (intptr_t i = 0; i < len; i++) {
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after
11340 11346
11341 RawOneByteString* OneByteString::New(intptr_t len, 11347 RawOneByteString* OneByteString::New(intptr_t len,
11342 Heap::Space space) { 11348 Heap::Space space) {
11343 ASSERT(Isolate::Current() == Dart::vm_isolate() || 11349 ASSERT(Isolate::Current() == Dart::vm_isolate() ||
11344 Isolate::Current()->object_store()->one_byte_string_class() != 11350 Isolate::Current()->object_store()->one_byte_string_class() !=
11345 Class::null()); 11351 Class::null());
11346 if (len < 0 || len > kMaxElements) { 11352 if (len < 0 || len > kMaxElements) {
11347 // This should be caught before we reach here. 11353 // This should be caught before we reach here.
11348 FATAL1("Fatal error in OneByteString::New: invalid len %"Pd"\n", len); 11354 FATAL1("Fatal error in OneByteString::New: invalid len %"Pd"\n", len);
11349 } 11355 }
11350 String& result = String::Handle();
11351 { 11356 {
11352 RawObject* raw = Object::Allocate(OneByteString::kClassId, 11357 RawObject* raw = Object::Allocate(OneByteString::kClassId,
11353 OneByteString::InstanceSize(len), 11358 OneByteString::InstanceSize(len),
11354 space); 11359 space);
11355 NoGCScope no_gc; 11360 NoGCScope no_gc;
11356 result ^= raw; 11361 RawOneByteString* result = reinterpret_cast<RawOneByteString*>(raw);
11357 result.SetLength(len); 11362 result->ptr()->length_ = Smi::New(len);
11358 result.SetHash(0); 11363 result->ptr()->hash_ = 0;
11364 return result;
11359 } 11365 }
11360 return OneByteString::raw(result);
11361 } 11366 }
11362 11367
11363 11368
11364 RawOneByteString* OneByteString::New(const uint8_t* characters, 11369 RawOneByteString* OneByteString::New(const uint8_t* characters,
11365 intptr_t len, 11370 intptr_t len,
11366 Heap::Space space) { 11371 Heap::Space space) {
11367 const String& result = String::Handle(OneByteString::New(len, space)); 11372 const String& result = String::Handle(OneByteString::New(len, space));
11368 if (len > 0) { 11373 if (len > 0) {
11369 NoGCScope no_gc; 11374 NoGCScope no_gc;
11370 memmove(CharAddr(result, 0), characters, len); 11375 memmove(CharAddr(result, 0), characters, len);
(...skipping 1702 matching lines...) Expand 10 before | Expand all | Expand 10 after
13073 } 13078 }
13074 return result.raw(); 13079 return result.raw();
13075 } 13080 }
13076 13081
13077 13082
13078 const char* WeakProperty::ToCString() const { 13083 const char* WeakProperty::ToCString() const {
13079 return "_WeakProperty"; 13084 return "_WeakProperty";
13080 } 13085 }
13081 13086
13082 } // namespace dart 13087 } // namespace dart
OLDNEW
« 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