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

Unified Diff: runtime/vm/object.h

Issue 8383029: Implement external strings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fully displace external string metadata Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/object.h
diff --git a/runtime/vm/object.h b/runtime/vm/object.h
index d5e8434356f4ab5049afcb8106f22f4c46fd7f69..a117a1148b2c1ec959baf0971bc9ab87074691a4 100644
--- a/runtime/vm/object.h
+++ b/runtime/vm/object.h
@@ -2378,10 +2378,16 @@ class Double : public Number {
// String may not be '\0' terminated.
class String : public Instance {
public:
+ typedef void (*PeerFinalizer)(void *peer);
siva 2011/11/18 23:26:09 dart_api.h is included in this file so can we use
cshapiro 2011/11/19 01:08:29 Good idea. I am thinking of getting rid of this t
+
// We use 30 bits for the hash code so that we consistently use a
// 32bit Smi representation for the hash code on all architectures.
static const intptr_t kHashBits = 30;
+ static const intptr_t kOneByteChar = 1;
+ static const intptr_t kTwoByteChar = 2;
+ static const intptr_t kFourByteChar = 4;
+
intptr_t Length() const { return Smi::Value(raw_ptr()->length_); }
static intptr_t length_offset() { return OFFSET_OF(RawString, length_); }
@@ -2394,6 +2400,8 @@ class String : public Instance {
virtual int32_t CharAt(intptr_t index) const;
+ virtual intptr_t CharSize() const;
+
bool Equals(const String& str, intptr_t begin_index, intptr_t len) const;
bool Equals(const char* str) const;
bool Equals(const uint8_t* characters, intptr_t len) const;
@@ -2422,6 +2430,22 @@ class String : public Instance {
Heap::Space space = Heap::kNew);
static RawString* New(const String& str, Heap::Space space = Heap::kNew);
+ static RawString* NewExternal(const uint8_t* characters,
+ intptr_t len,
+ void* peer,
+ PeerFinalizer callback,
+ Heap::Space = Heap::kNew);
+ static RawString* NewExternal(const uint16_t* characters,
+ intptr_t len,
+ void* peer,
+ PeerFinalizer callback,
+ Heap::Space = Heap::kNew);
+ static RawString* NewExternal(const uint32_t* characters,
+ intptr_t len,
+ void* peer,
+ PeerFinalizer callback,
+ Heap::Space = Heap::kNew);
+
static void Copy(const String& dst,
intptr_t dst_offset,
const uint8_t* characters,
@@ -2499,6 +2523,10 @@ class OneByteString : public String {
return *CharAddr(index);
}
+ virtual intptr_t CharSize() const {
+ return kOneByteChar;
+ }
+
static intptr_t data_offset() { return OFFSET_OF(RawOneByteString, data_); }
static intptr_t InstanceSize() {
@@ -2531,11 +2559,6 @@ class OneByteString : public String {
intptr_t len,
Heap::Space space);
- static RawString* SubString(const OneByteString& str,
- intptr_t begin_index,
- intptr_t length,
- Heap::Space space);
-
static RawOneByteString* Transform(int32_t (*mapping)(int32_t ch),
const String& str,
Heap::Space space);
@@ -2559,6 +2582,10 @@ class TwoByteString : public String {
return *CharAddr(index);
}
+ virtual intptr_t CharSize() const {
+ return kTwoByteChar;
+ }
+
static intptr_t InstanceSize() {
ASSERT(sizeof(RawTwoByteString) == OFFSET_OF(RawTwoByteString, data_));
return 0;
@@ -2586,11 +2613,6 @@ class TwoByteString : public String {
intptr_t len,
Heap::Space space);
- static RawString* SubString(const TwoByteString& str,
- intptr_t begin_index,
- intptr_t length,
- Heap::Space space);
-
static RawTwoByteString* Transform(int32_t (*mapping)(int32_t ch),
const String& str,
Heap::Space space);
@@ -2613,6 +2635,10 @@ class FourByteString : public String {
return *CharAddr(index);
}
+ virtual intptr_t CharSize() const {
+ return kFourByteChar;
+ }
+
static intptr_t InstanceSize() {
ASSERT(sizeof(RawFourByteString) == OFFSET_OF(RawFourByteString, data_));
return 0;
@@ -2637,11 +2663,6 @@ class FourByteString : public String {
intptr_t len,
Heap::Space space);
- static RawString* SubString(const FourByteString& str,
- intptr_t begin_index,
- intptr_t length,
- Heap::Space space);
-
static RawFourByteString* Transform(int32_t (*mapping)(int32_t ch),
const String& str,
Heap::Space space);
@@ -2658,6 +2679,117 @@ class FourByteString : public String {
};
+class ExternalOneByteString : public String {
+ public:
+ virtual int32_t CharAt(intptr_t index) const {
+ return *CharAddr(index);
+ }
+
+ virtual intptr_t CharSize() const {
+ return kOneByteChar;
+ }
+
+ static intptr_t InstanceSize() {
+ return RoundedAllocationSize(sizeof(RawExternalOneByteString));
+ }
+
+ static RawExternalOneByteString* New(const uint8_t* characters,
+ intptr_t len,
+ void* peer,
+ PeerFinalizer callback,
+ Heap::Space space);
+
+ private:
+ const uint8_t* CharAddr(intptr_t index) const {
+ // TODO(iposva): Determine if we should throw an exception here.
+ ASSERT((index >= 0) && (index < Length()));
+ return &raw_ptr()->external_data_->data_[index];
siva 2011/11/18 23:26:09 I normally put a paren around as follows: return &
cshapiro 2011/11/19 01:08:29 Sure, why not? Fixed here and in the two cases be
+ }
+
+ void SetExternalData(RawExternalStringData<uint8_t>* data) {
+ raw_ptr()->external_data_ = data;
+ }
+
+ HEAP_OBJECT_IMPLEMENTATION(ExternalOneByteString, String);
+ friend class Class;
+ friend class String;
+};
+
+
+class ExternalTwoByteString : public String {
+ public:
+ virtual int32_t CharAt(intptr_t index) const {
+ return *CharAddr(index);
+ }
+
+ virtual intptr_t CharSize() const {
+ return kTwoByteChar;
+ }
+
+ static intptr_t InstanceSize() {
+ return RoundedAllocationSize(sizeof(RawExternalTwoByteString));
+ }
+
+ static RawExternalTwoByteString* New(const uint16_t* characters,
+ intptr_t len,
+ void* peer,
+ PeerFinalizer callback,
+ Heap::Space space = Heap::kNew);
+
+ private:
+ const uint16_t* CharAddr(intptr_t index) const {
+ // TODO(iposva): Determine if we should throw an exception here.
+ ASSERT((index >= 0) && (index < Length()));
+ return &raw_ptr()->external_data_->data_[index];
+ }
+
+ void SetExternalData(RawExternalStringData<uint16_t>* data) {
+ raw_ptr()->external_data_ = data;
+ }
+
+ HEAP_OBJECT_IMPLEMENTATION(ExternalTwoByteString, String);
+ friend class Class;
+ friend class String;
+};
+
+
+class ExternalFourByteString : public String {
+ public:
+ virtual int32_t CharAt(intptr_t index) const {
+ return *CharAddr(index);
+ }
+
+ virtual intptr_t CharSize() const {
+ return kFourByteChar;
+ }
+
+ static intptr_t InstanceSize() {
+ return RoundedAllocationSize(sizeof(RawExternalFourByteString));
+ }
+
+ static RawExternalFourByteString* New(const uint32_t* characters,
+ intptr_t len,
+ void* peer,
+ PeerFinalizer callback,
+ Heap::Space space = Heap::kNew);
+
+ private:
+ const uint32_t* CharAddr(intptr_t index) const {
+ // TODO(iposva): Determine if we should throw an exception here.
+ ASSERT((index >= 0) && (index < Length()));
+ return &raw_ptr()->external_data_->data_[index];
+ }
+
+ void SetExternalData(RawExternalStringData<uint32_t>* data) {
+ raw_ptr()->external_data_ = data;
+ }
+
+ HEAP_OBJECT_IMPLEMENTATION(ExternalFourByteString, String);
+ friend class Class;
+ friend class String;
+};
+
+
class Bool : public Instance {
public:
bool value() const {

Powered by Google App Engine
This is Rietveld 408576698