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

Side by Side Diff: runtime/vm/object.h

Issue 1666113002: Improve performance of Library::LookupLibrary(const String&). (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | runtime/vm/object.cc » ('j') | runtime/vm/object.cc » ('J')
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 #ifndef VM_OBJECT_H_ 5 #ifndef VM_OBJECT_H_
6 #define VM_OBJECT_H_ 6 #define VM_OBJECT_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/utils.h" 10 #include "platform/utils.h"
(...skipping 6270 matching lines...) Expand 10 before | Expand all | Expand 10 after
6281 6281
6282 intptr_t Hash() const { 6282 intptr_t Hash() const {
6283 intptr_t result = Smi::Value(raw_ptr()->hash_); 6283 intptr_t result = Smi::Value(raw_ptr()->hash_);
6284 if (result != 0) { 6284 if (result != 0) {
6285 return result; 6285 return result;
6286 } 6286 }
6287 result = String::Hash(*this, 0, this->Length()); 6287 result = String::Hash(*this, 0, this->Length());
6288 this->SetHash(result); 6288 this->SetHash(result);
6289 return result; 6289 return result;
6290 } 6290 }
6291
6291 bool HasHash() const { 6292 bool HasHash() const {
6292 ASSERT(Smi::New(0) == NULL); 6293 ASSERT(Smi::New(0) == NULL);
6293 return (raw_ptr()->hash_ != NULL); 6294 return (raw_ptr()->hash_ != NULL);
6294 } 6295 }
6295 6296
6296 static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); } 6297 static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); }
6297 static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len); 6298 static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len);
6298 static intptr_t Hash(const char* characters, intptr_t len); 6299 static intptr_t Hash(const char* characters, intptr_t len);
6299 static intptr_t Hash(const uint16_t* characters, intptr_t len); 6300 static intptr_t Hash(const uint16_t* characters, intptr_t len);
6300 static intptr_t Hash(const int32_t* characters, intptr_t len); 6301 static intptr_t Hash(const int32_t* characters, intptr_t len);
6301 static intptr_t HashRawSymbol(const RawString* symbol) { 6302 static intptr_t HashRawSymbol(const RawString* symbol) {
6302 ASSERT(symbol->IsCanonical()); 6303 ASSERT(symbol->IsCanonical());
6303 intptr_t result = Smi::Value(symbol->ptr()->hash_); 6304 intptr_t result = Smi::Value(symbol->ptr()->hash_);
6304 ASSERT(result != 0); 6305 ASSERT(result != 0);
6305 return result; 6306 return result;
6306 } 6307 }
6307 6308
6308 // Returns the hash of str1 + str2. 6309 // Returns the hash of str1 + str2.
6309 static intptr_t HashConcat(const String& str1, const String& str2); 6310 static intptr_t HashConcat(const String& str1, const String& str2);
6310 6311
6311 virtual RawObject* HashCode() const { return Integer::New(Hash()); } 6312 virtual RawObject* HashCode() const { return Integer::New(Hash()); }
6312 6313
6313 uint16_t CharAt(intptr_t index) const; 6314 uint16_t CharAt(intptr_t index) const;
6314 6315
6315 Scanner::CharAtFunc CharAtFunc() const; 6316 Scanner::CharAtFunc CharAtFunc() const;
6316 6317
6317 intptr_t CharSize() const; 6318 intptr_t CharSize() const;
6318 6319
6319 inline bool Equals(const String& str) const; 6320 inline bool Equals(const String& str) const;
6320 inline bool Equals(const String& str, 6321
6321 intptr_t begin_index, // begin index on 'str'. 6322 bool Equals(const String& str,
6322 intptr_t len) const; // len on 'str'. 6323 intptr_t begin_index, // begin index on 'str'.
6324 intptr_t len) const; // len on 'str'.
6323 6325
6324 // Compares to a '\0' terminated array of UTF-8 encoded characters. 6326 // Compares to a '\0' terminated array of UTF-8 encoded characters.
6325 bool Equals(const char* cstr) const; 6327 bool Equals(const char* cstr) const;
6326 6328
6327 // Compares to an array of Latin-1 encoded characters. 6329 // Compares to an array of Latin-1 encoded characters.
6328 bool EqualsLatin1(const uint8_t* characters, intptr_t len) const { 6330 bool EqualsLatin1(const uint8_t* characters, intptr_t len) const {
6329 return Equals(characters, len); 6331 return Equals(characters, len);
6330 } 6332 }
6331 6333
6332 // Compares to an array of UTF-16 encoded characters. 6334 // Compares to an array of UTF-16 encoded characters.
(...skipping 2011 matching lines...) Expand 10 before | Expand all | Expand 10 after
8344 for (intptr_t i = 0; i < num_fields; i++) { 8346 for (intptr_t i = 0; i < num_fields; i++) {
8345 field_values[i] = fields[i]; 8347 field_values[i] = fields[i];
8346 } 8348 }
8347 } 8349 }
8348 8350
8349 8351
8350 bool String::Equals(const String& str) const { 8352 bool String::Equals(const String& str) const {
8351 if (raw() == str.raw()) { 8353 if (raw() == str.raw()) {
8352 return true; // Both handles point to the same raw instance. 8354 return true; // Both handles point to the same raw instance.
8353 } 8355 }
8354 if (str.IsNull()) { 8356 if (str.IsNull()) {
kasperl 2016/02/05 05:09:26 This takes care of the null check I removed from S
Ivan Posva 2016/02/05 05:57:42 Acknowledged.
8355 return false; 8357 return false;
8356 } 8358 }
8359 if (IsCanonical() && str.IsCanonical()) {
8360 return false; // Two symbols that aren't identical aren't equal.
8361 }
8362 if (HasHash() && str.HasHash() && (Hash() != str.Hash())) {
8363 return false; // Both sides have hash codes and they do not match.
8364 }
8357 return Equals(str, 0, str.Length()); 8365 return Equals(str, 0, str.Length());
8358 } 8366 }
8359 8367
8360 8368
8361 bool String::Equals(const String& str,
8362 intptr_t begin_index,
8363 intptr_t len) const {
8364 ASSERT(begin_index >= 0);
8365 ASSERT((begin_index == 0) || (begin_index < str.Length()));
8366 ASSERT(len >= 0);
8367 ASSERT(len <= str.Length());
8368 if (len != this->Length()) {
8369 return false; // Lengths don't match.
8370 }
8371 for (intptr_t i = 0; i < len; i++) {
8372 if (this->CharAt(i) != str.CharAt(begin_index + i)) {
8373 return false;
8374 }
8375 }
8376 return true;
8377 }
8378
8379
8380 intptr_t Library::UrlHash() const { 8369 intptr_t Library::UrlHash() const {
8381 intptr_t result = Smi::Value(url()->ptr()->hash_); 8370 intptr_t result = Smi::Value(url()->ptr()->hash_);
8382 ASSERT(result != 0); 8371 ASSERT(result != 0);
8383 return result; 8372 return result;
8384 } 8373 }
8385 8374
8386 8375
8387 void MegamorphicCache::SetEntry(const Array& array, 8376 void MegamorphicCache::SetEntry(const Array& array,
8388 intptr_t index, 8377 intptr_t index,
8389 const Smi& class_id, 8378 const Smi& class_id,
8390 const Function& target) { 8379 const Function& target) {
8391 array.SetAt((index * kEntryLength) + kClassIdIndex, class_id); 8380 array.SetAt((index * kEntryLength) + kClassIdIndex, class_id);
8392 array.SetAt((index * kEntryLength) + kTargetFunctionIndex, target); 8381 array.SetAt((index * kEntryLength) + kTargetFunctionIndex, target);
8393 } 8382 }
8394 8383
8395 8384
8396 RawObject* MegamorphicCache::GetClassId(const Array& array, intptr_t index) { 8385 RawObject* MegamorphicCache::GetClassId(const Array& array, intptr_t index) {
8397 return array.At((index * kEntryLength) + kClassIdIndex); 8386 return array.At((index * kEntryLength) + kClassIdIndex);
8398 } 8387 }
8399 8388
8400 8389
8401 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, 8390 RawObject* MegamorphicCache::GetTargetFunction(const Array& array,
8402 intptr_t index) { 8391 intptr_t index) {
8403 return array.At((index * kEntryLength) + kTargetFunctionIndex); 8392 return array.At((index * kEntryLength) + kTargetFunctionIndex);
8404 } 8393 }
8405 8394
8406 } // namespace dart 8395 } // namespace dart
8407 8396
8408 #endif // VM_OBJECT_H_ 8397 #endif // VM_OBJECT_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/object.cc » ('j') | runtime/vm/object.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698