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

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

Issue 560113002: Narrow String::CharAt from int32_t to uint16_t. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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 5506 matching lines...) Expand 10 before | Expand all | Expand 10 after
5517 intptr_t result = Smi::Value(symbol->ptr()->hash_); 5517 intptr_t result = Smi::Value(symbol->ptr()->hash_);
5518 ASSERT(result != 0); 5518 ASSERT(result != 0);
5519 return result; 5519 return result;
5520 } 5520 }
5521 5521
5522 // Returns the hash of str1 + str2. 5522 // Returns the hash of str1 + str2.
5523 static intptr_t HashConcat(const String& str1, const String& str2); 5523 static intptr_t HashConcat(const String& str1, const String& str2);
5524 5524
5525 virtual RawObject* HashCode() const { return Integer::New(Hash()); } 5525 virtual RawObject* HashCode() const { return Integer::New(Hash()); }
5526 5526
5527 int32_t CharAt(intptr_t index) const; 5527 uint16_t CharAt(intptr_t index) const;
5528 5528
5529 Scanner::CharAtFunc CharAtFunc() const; 5529 Scanner::CharAtFunc CharAtFunc() const;
5530 5530
5531 intptr_t CharSize() const; 5531 intptr_t CharSize() const;
5532 5532
5533 inline bool Equals(const String& str) const; 5533 inline bool Equals(const String& str) const;
5534 inline bool Equals(const String& str, 5534 inline bool Equals(const String& str,
5535 intptr_t begin_index, // begin index on 'str'. 5535 intptr_t begin_index, // begin index on 'str'.
5536 intptr_t len) const; // len on 'str'. 5536 intptr_t len) const; // len on 'str'.
5537 5537
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
5747 friend class TwoByteString; 5747 friend class TwoByteString;
5748 friend class ExternalOneByteString; 5748 friend class ExternalOneByteString;
5749 friend class ExternalTwoByteString; 5749 friend class ExternalTwoByteString;
5750 // So that the MarkingVisitor can print a debug string from a NoHandleScope. 5750 // So that the MarkingVisitor can print a debug string from a NoHandleScope.
5751 friend class MarkingVisitor; 5751 friend class MarkingVisitor;
5752 }; 5752 };
5753 5753
5754 5754
5755 class OneByteString : public AllStatic { 5755 class OneByteString : public AllStatic {
5756 public: 5756 public:
5757 static int32_t CharAt(const String& str, intptr_t index) { 5757 static uint16_t CharAt(const String& str, intptr_t index) {
5758 return *CharAddr(str, index); 5758 return *CharAddr(str, index);
5759 } 5759 }
5760 5760
5761 static void SetCharAt(const String& str, intptr_t index, uint8_t code_point) { 5761 static void SetCharAt(const String& str, intptr_t index, uint8_t code_unit) {
5762 *CharAddr(str, index) = code_point; 5762 *CharAddr(str, index) = code_unit;
5763 } 5763 }
5764 static RawOneByteString* EscapeSpecialCharacters(const String& str); 5764 static RawOneByteString* EscapeSpecialCharacters(const String& str);
5765 // We use the same maximum elements for all strings. 5765 // We use the same maximum elements for all strings.
5766 static const intptr_t kBytesPerElement = 1; 5766 static const intptr_t kBytesPerElement = 1;
5767 static const intptr_t kMaxElements = String::kMaxElements; 5767 static const intptr_t kMaxElements = String::kMaxElements;
5768 5768
5769 static intptr_t data_offset() { 5769 static intptr_t data_offset() {
5770 return OFFSET_OF_RETURNED_VALUE(RawOneByteString, data); 5770 return OFFSET_OF_RETURNED_VALUE(RawOneByteString, data);
5771 } 5771 }
5772 5772
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
5876 friend class Class; 5876 friend class Class;
5877 friend class String; 5877 friend class String;
5878 friend class ExternalOneByteString; 5878 friend class ExternalOneByteString;
5879 friend class SnapshotReader; 5879 friend class SnapshotReader;
5880 friend class StringHasher; 5880 friend class StringHasher;
5881 }; 5881 };
5882 5882
5883 5883
5884 class TwoByteString : public AllStatic { 5884 class TwoByteString : public AllStatic {
5885 public: 5885 public:
5886 static int32_t CharAt(const String& str, intptr_t index) { 5886 static uint16_t CharAt(const String& str, intptr_t index) {
5887 return *CharAddr(str, index); 5887 return *CharAddr(str, index);
5888 } 5888 }
5889 5889
5890 static void SetCharAt(const String& str, intptr_t index, uint16_t ch) { 5890 static void SetCharAt(const String& str, intptr_t index, uint16_t ch) {
5891 *CharAddr(str, index) = ch; 5891 *CharAddr(str, index) = ch;
5892 } 5892 }
5893 5893
5894 static RawTwoByteString* EscapeSpecialCharacters(const String& str); 5894 static RawTwoByteString* EscapeSpecialCharacters(const String& str);
5895 5895
5896 // We use the same maximum elements for all strings. 5896 // We use the same maximum elements for all strings.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
5976 Snapshot::Kind kind); 5976 Snapshot::Kind kind);
5977 5977
5978 friend class Class; 5978 friend class Class;
5979 friend class String; 5979 friend class String;
5980 friend class SnapshotReader; 5980 friend class SnapshotReader;
5981 }; 5981 };
5982 5982
5983 5983
5984 class ExternalOneByteString : public AllStatic { 5984 class ExternalOneByteString : public AllStatic {
5985 public: 5985 public:
5986 static int32_t CharAt(const String& str, intptr_t index) { 5986 static uint16_t CharAt(const String& str, intptr_t index) {
5987 return *CharAddr(str, index); 5987 return *CharAddr(str, index);
5988 } 5988 }
5989 5989
5990 static void* GetPeer(const String& str) { 5990 static void* GetPeer(const String& str) {
5991 return raw_ptr(str)->external_data_->peer(); 5991 return raw_ptr(str)->external_data_->peer();
5992 } 5992 }
5993 5993
5994 // We use the same maximum elements for all strings. 5994 // We use the same maximum elements for all strings.
5995 static const intptr_t kBytesPerElement = 1; 5995 static const intptr_t kBytesPerElement = 1;
5996 static const intptr_t kMaxElements = String::kMaxElements; 5996 static const intptr_t kMaxElements = String::kMaxElements;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
6053 } 6053 }
6054 6054
6055 friend class Class; 6055 friend class Class;
6056 friend class String; 6056 friend class String;
6057 friend class SnapshotReader; 6057 friend class SnapshotReader;
6058 }; 6058 };
6059 6059
6060 6060
6061 class ExternalTwoByteString : public AllStatic { 6061 class ExternalTwoByteString : public AllStatic {
6062 public: 6062 public:
6063 static int32_t CharAt(const String& str, intptr_t index) { 6063 static uint16_t CharAt(const String& str, intptr_t index) {
6064 return *CharAddr(str, index); 6064 return *CharAddr(str, index);
6065 } 6065 }
6066 6066
6067 static void* GetPeer(const String& str) { 6067 static void* GetPeer(const String& str) {
6068 return raw_ptr(str)->external_data_->peer(); 6068 return raw_ptr(str)->external_data_->peer();
6069 } 6069 }
6070 6070
6071 // We use the same maximum elements for all strings. 6071 // We use the same maximum elements for all strings.
6072 static const intptr_t kBytesPerElement = 2; 6072 static const intptr_t kBytesPerElement = 2;
6073 static const intptr_t kMaxElements = String::kMaxElements; 6073 static const intptr_t kMaxElements = String::kMaxElements;
(...skipping 1377 matching lines...) Expand 10 before | Expand all | Expand 10 after
7451 7451
7452 7452
7453 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, 7453 RawObject* MegamorphicCache::GetTargetFunction(const Array& array,
7454 intptr_t index) { 7454 intptr_t index) {
7455 return array.At((index * kEntryLength) + kTargetFunctionIndex); 7455 return array.At((index * kEntryLength) + kTargetFunctionIndex);
7456 } 7456 }
7457 7457
7458 } // namespace dart 7458 } // namespace dart
7459 7459
7460 #endif // VM_OBJECT_H_ 7460 #endif // VM_OBJECT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698