OLD | NEW |
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 10162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10173 hash_ += hash_ << 15; | 10173 hash_ += hash_ << 15; |
10174 hash_ = hash_ & ((static_cast<intptr_t>(1) << bits) - 1); | 10174 hash_ = hash_ & ((static_cast<intptr_t>(1) << bits) - 1); |
10175 ASSERT(hash_ <= static_cast<uint32_t>(kMaxInt32)); | 10175 ASSERT(hash_ <= static_cast<uint32_t>(kMaxInt32)); |
10176 return hash_ == 0 ? 1 : hash_; | 10176 return hash_ == 0 ? 1 : hash_; |
10177 } | 10177 } |
10178 private: | 10178 private: |
10179 uint32_t hash_; | 10179 uint32_t hash_; |
10180 }; | 10180 }; |
10181 | 10181 |
10182 | 10182 |
10183 intptr_t String::Hash() const { | |
10184 intptr_t result = Smi::Value(raw_ptr()->hash_); | |
10185 if (result != 0) { | |
10186 return result; | |
10187 } | |
10188 result = String::Hash(*this, 0, this->Length()); | |
10189 this->SetHash(result); | |
10190 return result; | |
10191 } | |
10192 | |
10193 | |
10194 intptr_t String::Hash(const String& str, intptr_t begin_index, intptr_t len) { | 10183 intptr_t String::Hash(const String& str, intptr_t begin_index, intptr_t len) { |
10195 ASSERT(begin_index >= 0); | 10184 ASSERT(begin_index >= 0); |
10196 ASSERT(len >= 0); | 10185 ASSERT(len >= 0); |
10197 ASSERT((begin_index + len) <= str.Length()); | 10186 ASSERT((begin_index + len) <= str.Length()); |
10198 StringHasher hasher; | 10187 StringHasher hasher; |
10199 CodePointIterator it(str, begin_index, len); | 10188 CodePointIterator it(str, begin_index, len); |
10200 while (it.Next()) { | 10189 while (it.Next()) { |
10201 hasher.Add(it.Current()); | 10190 hasher.Add(it.Current()); |
10202 } | 10191 } |
10203 return hasher.Finalize(String::kHashBits); | 10192 return hasher.Finalize(String::kHashBits); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10279 // Both handles point to the same raw instance. | 10268 // Both handles point to the same raw instance. |
10280 return true; | 10269 return true; |
10281 } | 10270 } |
10282 | 10271 |
10283 if (!other.IsString() || other.IsNull()) { | 10272 if (!other.IsString() || other.IsNull()) { |
10284 return false; | 10273 return false; |
10285 } | 10274 } |
10286 | 10275 |
10287 const String& other_string = String::Cast(other); | 10276 const String& other_string = String::Cast(other); |
10288 if (this->HasHash() && other_string.HasHash() && | 10277 if (this->HasHash() && other_string.HasHash() && |
10289 (this->Hash() != other_string.Hash())) { | 10278 (this->StringHash() != other_string.StringHash())) { |
10290 return false; // Both sides have a hash code and it does not match. | 10279 return false; // Both sides have a hash code and it does not match. |
10291 } | 10280 } |
10292 return Equals(other_string, 0, other_string.Length()); | 10281 return Equals(other_string, 0, other_string.Length()); |
10293 } | 10282 } |
10294 | 10283 |
10295 | 10284 |
10296 bool String::Equals(const char* cstr) const { | 10285 bool String::Equals(const char* cstr) const { |
10297 ASSERT(cstr != NULL); | 10286 ASSERT(cstr != NULL); |
10298 CodePointIterator it(*this); | 10287 CodePointIterator it(*this); |
10299 intptr_t len = strlen(cstr); | 10288 intptr_t len = strlen(cstr); |
(...skipping 2196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12496 } | 12485 } |
12497 return result.raw(); | 12486 return result.raw(); |
12498 } | 12487 } |
12499 | 12488 |
12500 | 12489 |
12501 const char* WeakProperty::ToCString() const { | 12490 const char* WeakProperty::ToCString() const { |
12502 return "_WeakProperty"; | 12491 return "_WeakProperty"; |
12503 } | 12492 } |
12504 | 12493 |
12505 } // namespace dart | 12494 } // namespace dart |
OLD | NEW |