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

Side by Side Diff: src/objects.cc

Issue 7622: - Eliminated superfluous type tests in IsMatch. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 12 years, 2 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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 5326 matching lines...) Expand 10 before | Expand all | Expand 10 after
5337 5337
5338 // The NumberKey uses carries the uint32_t as key. 5338 // The NumberKey uses carries the uint32_t as key.
5339 // This avoids allocation in HasProperty. 5339 // This avoids allocation in HasProperty.
5340 class NumberKey : public HashTableKey { 5340 class NumberKey : public HashTableKey {
5341 public: 5341 public:
5342 explicit NumberKey(uint32_t number) { 5342 explicit NumberKey(uint32_t number) {
5343 number_ = number; 5343 number_ = number;
5344 } 5344 }
5345 5345
5346 private: 5346 private:
5347 bool IsMatch(Object* other) { 5347 bool IsMatch(Object* number) {
5348 return number_ == ToUint32(other); 5348 return number_ == ToUint32(number);
5349 } 5349 }
5350 5350
5351 // Thomas Wang, Integer Hash Functions. 5351 // Thomas Wang, Integer Hash Functions.
5352 // http://www.concentric.net/~Ttwang/tech/inthash.htm 5352 // http://www.concentric.net/~Ttwang/tech/inthash.htm
5353 static uint32_t ComputeHash(uint32_t key) { 5353 static uint32_t ComputeHash(uint32_t key) {
5354 uint32_t hash = key; 5354 uint32_t hash = key;
5355 hash = ~hash + (hash << 15); // hash = (hash << 15) - hash - 1; 5355 hash = ~hash + (hash << 15); // hash = (hash << 15) - hash - 1;
5356 hash = hash ^ (hash >> 12); 5356 hash = hash ^ (hash >> 12);
5357 hash = hash + (hash << 2); 5357 hash = hash + (hash << 2);
5358 hash = hash ^ (hash >> 4); 5358 hash = hash ^ (hash >> 4);
(...skipping 25 matching lines...) Expand all
5384 }; 5384 };
5385 5385
5386 5386
5387 // StringKey simply carries a string object as key. 5387 // StringKey simply carries a string object as key.
5388 class StringKey : public HashTableKey { 5388 class StringKey : public HashTableKey {
5389 public: 5389 public:
5390 explicit StringKey(String* string) { 5390 explicit StringKey(String* string) {
5391 string_ = string; 5391 string_ = string;
5392 } 5392 }
5393 5393
5394 bool IsMatch(Object* other) { 5394 bool IsMatch(Object* string) {
5395 if (!other->IsString()) return false; 5395 return string_->Equals(String::cast(string));
5396 return string_->Equals(String::cast(other));
5397 } 5396 }
5398 5397
5399 uint32_t Hash() { return StringHash(string_); } 5398 uint32_t Hash() { return StringHash(string_); }
5400 5399
5401 HashFunction GetHashFunction() { return StringHash; } 5400 HashFunction GetHashFunction() { return StringHash; }
5402 5401
5403 Object* GetObject() { return string_; } 5402 Object* GetObject() { return string_; }
5404 5403
5405 static uint32_t StringHash(Object* obj) { 5404 static uint32_t StringHash(Object* obj) {
5406 return String::cast(obj)->Hash(); 5405 return String::cast(obj)->Hash();
5407 } 5406 }
5408 5407
5409 bool IsStringKey() { return true; } 5408 bool IsStringKey() { return true; }
5410 5409
5411 String* string_; 5410 String* string_;
5412 }; 5411 };
5413 5412
5414 // Utf8SymbolKey carries a vector of chars as key. 5413 // Utf8SymbolKey carries a vector of chars as key.
5415 class Utf8SymbolKey : public HashTableKey { 5414 class Utf8SymbolKey : public HashTableKey {
5416 public: 5415 public:
5417 explicit Utf8SymbolKey(Vector<const char> string) 5416 explicit Utf8SymbolKey(Vector<const char> string)
5418 : string_(string), length_field_(0) { } 5417 : string_(string), length_field_(0) { }
5419 5418
5420 bool IsMatch(Object* other) { 5419 bool IsMatch(Object* string) {
5421 if (!other->IsString()) return false; 5420 return String::cast(string)->IsEqualTo(string_);
5422 return String::cast(other)->IsEqualTo(string_);
5423 } 5421 }
5424 5422
5425 HashFunction GetHashFunction() { 5423 HashFunction GetHashFunction() {
5426 return StringHash; 5424 return StringHash;
5427 } 5425 }
5428 5426
5429 uint32_t Hash() { 5427 uint32_t Hash() {
5430 if (length_field_ != 0) return length_field_ >> String::kHashShift; 5428 if (length_field_ != 0) return length_field_ >> String::kHashShift;
5431 unibrow::Utf8InputBuffer<> buffer(string_.start(), 5429 unibrow::Utf8InputBuffer<> buffer(string_.start(),
5432 static_cast<unsigned>(string_.length())); 5430 static_cast<unsigned>(string_.length()));
(...skipping 23 matching lines...) Expand all
5456 5454
5457 // SymbolKey carries a string/symbol object as key. 5455 // SymbolKey carries a string/symbol object as key.
5458 class SymbolKey : public HashTableKey { 5456 class SymbolKey : public HashTableKey {
5459 public: 5457 public:
5460 explicit SymbolKey(String* string) : string_(string) { } 5458 explicit SymbolKey(String* string) : string_(string) { }
5461 5459
5462 HashFunction GetHashFunction() { 5460 HashFunction GetHashFunction() {
5463 return StringHash; 5461 return StringHash;
5464 } 5462 }
5465 5463
5466 bool IsMatch(Object* other) { 5464 bool IsMatch(Object* string) {
5467 if (!other->IsString()) return false; 5465 return String::cast(string)->Equals(string_);
5468 return String::cast(other)->Equals(string_);
5469 } 5466 }
5470 5467
5471 uint32_t Hash() { return string_->Hash(); } 5468 uint32_t Hash() { return string_->Hash(); }
5472 5469
5473 Object* GetObject() { 5470 Object* GetObject() {
5474 // If the string is a cons string, attempt to flatten it so that 5471 // If the string is a cons string, attempt to flatten it so that
5475 // symbols will most often be flat strings. 5472 // symbols will most often be flat strings.
5476 if (string_->IsConsString()) { 5473 if (string_->IsConsString()) {
5477 ConsString* cons_string = ConsString::cast(string_); 5474 ConsString* cons_string = ConsString::cast(string_);
5478 cons_string->TryFlatten(); 5475 cons_string->TryFlatten();
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
5705 } 5702 }
5706 5703
5707 5704
5708 // SymbolsKey used for HashTable where key is array of symbols. 5705 // SymbolsKey used for HashTable where key is array of symbols.
5709 class SymbolsKey : public HashTableKey { 5706 class SymbolsKey : public HashTableKey {
5710 public: 5707 public:
5711 explicit SymbolsKey(FixedArray* symbols) { 5708 explicit SymbolsKey(FixedArray* symbols) {
5712 symbols_ = symbols; 5709 symbols_ = symbols;
5713 } 5710 }
5714 5711
5715 bool IsMatch(Object* other) { 5712 bool IsMatch(Object* symbols) {
5716 if (!other->IsFixedArray()) return false; 5713 FixedArray* o = FixedArray::cast(symbols);
5717 FixedArray* o = FixedArray::cast(other);
5718 int len = symbols_->length(); 5714 int len = symbols_->length();
5719 if (o->length() != len) return false; 5715 if (o->length() != len) return false;
5720 for (int i = 0; i < len; i++) { 5716 for (int i = 0; i < len; i++) {
5721 if (o->get(i) != symbols_->get(i)) return false; 5717 if (o->get(i) != symbols_->get(i)) return false;
5722 } 5718 }
5723 return true; 5719 return true;
5724 } 5720 }
5725 5721
5726 uint32_t Hash() { return SymbolsHash(symbols_); } 5722 uint32_t Hash() { return SymbolsHash(symbols_); }
5727 5723
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
6428 // No break point. 6424 // No break point.
6429 if (break_point_objects()->IsUndefined()) return 0; 6425 if (break_point_objects()->IsUndefined()) return 0;
6430 // Single beak point. 6426 // Single beak point.
6431 if (!break_point_objects()->IsFixedArray()) return 1; 6427 if (!break_point_objects()->IsFixedArray()) return 1;
6432 // Multiple break points. 6428 // Multiple break points.
6433 return FixedArray::cast(break_point_objects())->length(); 6429 return FixedArray::cast(break_point_objects())->length();
6434 } 6430 }
6435 6431
6436 6432
6437 } } // namespace v8::internal 6433 } } // namespace v8::internal
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