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

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

Issue 474033002: Ensure that hash for a symbol is not set to 0 when it is made external. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 4 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
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 5371 matching lines...) Expand 10 before | Expand all | Expand 10 after
5382 5382
5383 intptr_t Hash() const { 5383 intptr_t Hash() const {
5384 intptr_t result = Smi::Value(raw_ptr()->hash_); 5384 intptr_t result = Smi::Value(raw_ptr()->hash_);
5385 if (result != 0) { 5385 if (result != 0) {
5386 return result; 5386 return result;
5387 } 5387 }
5388 result = String::Hash(*this, 0, this->Length()); 5388 result = String::Hash(*this, 0, this->Length());
5389 this->SetHash(result); 5389 this->SetHash(result);
5390 return result; 5390 return result;
5391 } 5391 }
5392 bool HasHash() const {
5393 ASSERT(Smi::New(0) == NULL);
5394 return (raw_ptr()->hash_ != NULL);
Ivan Posva 2014/08/14 20:42:12 NULL? Shouldn't that be a Smi::Value(...) != 0?
siva 2014/08/14 21:04:57 Let me change this in a CL by itself, I want to ma
5395 }
5392 5396
5393 static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); } 5397 static intptr_t hash_offset() { return OFFSET_OF(RawString, hash_); }
5394 static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len); 5398 static intptr_t Hash(const String& str, intptr_t begin_index, intptr_t len);
5395 static intptr_t HashLatin1(const uint8_t* characters, intptr_t len); 5399 static intptr_t HashLatin1(const uint8_t* characters, intptr_t len);
5396 static intptr_t Hash(const uint16_t* characters, intptr_t len); 5400 static intptr_t Hash(const uint16_t* characters, intptr_t len);
5397 static intptr_t Hash(const int32_t* characters, intptr_t len); 5401 static intptr_t Hash(const int32_t* characters, intptr_t len);
5398 static intptr_t HashRawSymbol(const RawString* symbol) { 5402 static intptr_t HashRawSymbol(const RawString* symbol) {
5399 ASSERT(symbol->IsCanonical()); 5403 ASSERT(symbol->IsCanonical());
5400 intptr_t result = Smi::Value(symbol->ptr()->hash_); 5404 intptr_t result = Smi::Value(symbol->ptr()->hash_);
5401 ASSERT(result != 0); 5405 ASSERT(result != 0);
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
5595 intptr_t end, 5599 intptr_t end,
5596 double* result); 5600 double* result);
5597 5601
5598 protected: 5602 protected:
5599 // These two operate on an array of Latin-1 encoded characters. 5603 // These two operate on an array of Latin-1 encoded characters.
5600 // They are protected to avoid mistaking Latin-1 for UTF-8, but used 5604 // They are protected to avoid mistaking Latin-1 for UTF-8, but used
5601 // by friendly templated code (e.g., Symbols). 5605 // by friendly templated code (e.g., Symbols).
5602 bool Equals(const uint8_t* characters, intptr_t len) const; 5606 bool Equals(const uint8_t* characters, intptr_t len) const;
5603 static intptr_t Hash(const uint8_t* characters, intptr_t len); 5607 static intptr_t Hash(const uint8_t* characters, intptr_t len);
5604 5608
5605 bool HasHash() const {
5606 ASSERT(Smi::New(0) == NULL);
5607 return (raw_ptr()->hash_ != NULL);
5608 }
5609
5610 void SetLength(intptr_t value) const { 5609 void SetLength(intptr_t value) const {
5611 // This is only safe because we create a new Smi, which does not cause 5610 // This is only safe because we create a new Smi, which does not cause
5612 // heap allocation. 5611 // heap allocation.
5613 raw_ptr()->length_ = Smi::New(value); 5612 raw_ptr()->length_ = Smi::New(value);
5614 } 5613 }
5615 5614
5616 void SetHash(intptr_t value) const { 5615 void SetHash(intptr_t value) const {
5617 // This is only safe because we create a new Smi, which does not cause 5616 // This is only safe because we create a new Smi, which does not cause
5618 // heap allocation. 5617 // heap allocation.
5619 raw_ptr()->hash_ = Smi::New(value); 5618 raw_ptr()->hash_ = Smi::New(value);
(...skipping 1696 matching lines...) Expand 10 before | Expand all | Expand 10 after
7316 7315
7317 7316
7318 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, 7317 RawObject* MegamorphicCache::GetTargetFunction(const Array& array,
7319 intptr_t index) { 7318 intptr_t index) {
7320 return array.At((index * kEntryLength) + kTargetFunctionIndex); 7319 return array.At((index * kEntryLength) + kTargetFunctionIndex);
7321 } 7320 }
7322 7321
7323 } // namespace dart 7322 } // namespace dart
7324 7323
7325 #endif // VM_OBJECT_H_ 7324 #endif // VM_OBJECT_H_
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('k') | runtime/vm/object.cc » ('j') | runtime/vm/object.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698