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

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: Finish native peer support Created 9 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 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 7c815a806451a0549741d3f722e71e7363b2e710..c2d45b08b1a934ead373dc9c77400b71e6482c5b 100644
--- a/runtime/vm/object.h
+++ b/runtime/vm/object.h
@@ -2355,6 +2355,10 @@ class String : public Instance {
// 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_); }
@@ -2367,6 +2371,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;
@@ -2395,6 +2401,19 @@ 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,
+ Heap::Space = Heap::kNew);
+ static RawString* NewExternal(const uint16_t* characters,
+ intptr_t len,
+ void* peer,
+ Heap::Space = Heap::kNew);
+ static RawString* NewExternal(const uint32_t* characters,
+ intptr_t len,
+ void* peer,
+ Heap::Space = Heap::kNew);
+
static void Copy(const String& dst,
intptr_t dst_offset,
const uint8_t* characters,
@@ -2472,6 +2491,10 @@ class OneByteString : public String {
return *CharAddr(index);
}
+ virtual intptr_t CharSize() const {
+ return kOneByteChar;
+ }
+
static intptr_t InstanceSize() {
ASSERT(sizeof(RawOneByteString) == OFFSET_OF(RawOneByteString, data_));
return 0;
@@ -2502,11 +2525,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);
@@ -2530,6 +2548,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;
@@ -2557,11 +2579,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);
@@ -2584,6 +2601,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;
@@ -2608,11 +2629,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);
@@ -2629,6 +2645,138 @@ 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;
+ }
+
+ void* Peer() const {
+ return raw_ptr()->peer_;
+ }
+
+ static intptr_t InstanceSize() {
+ return RoundedAllocationSize(sizeof(RawExternalOneByteString));
+ }
+
+ static RawExternalOneByteString* New(const uint8_t* characters,
+ intptr_t len,
+ void* peer,
+ Heap::Space space);
+
+ private:
+ 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()->data_[index];
+ }
+
+ void SetData(const uint8_t* characters) {
+ raw_ptr()->data_ = const_cast<uint8_t*>(characters);
+ }
+
+ void SetPeer(void* peer) {
+ raw_ptr()->peer_ = peer;
+ }
+
+ 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));
+ }
+
+ void* Peer() const {
+ return raw_ptr()->peer_;
+ }
+
+ static RawExternalTwoByteString* New(const uint16_t* characters,
+ intptr_t len,
+ void* peer,
+ Heap::Space space = Heap::kNew);
+
+ private:
+ 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()->data_[index];
+ }
+
+ void SetData(const uint16_t* characters) {
+ raw_ptr()->data_ = const_cast<uint16_t*>(characters);
+ }
+
+ void SetPeer(void* peer) {
+ raw_ptr()->peer_ = peer;
+ }
+
+ 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;
+ }
+
+ void* Peer() const {
+ return raw_ptr()->peer_;
+ }
+
+ static intptr_t InstanceSize() {
+ return RoundedAllocationSize(sizeof(RawExternalFourByteString));
+ }
+
+ static RawExternalFourByteString* New(const uint32_t* characters,
+ intptr_t len,
+ void* peer,
+ Heap::Space space = Heap::kNew);
+
+ private:
+ 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()->data_[index];
+ }
+
+ void SetData(const uint32_t* characters) {
+ raw_ptr()->data_ = const_cast<uint32_t*>(characters);
+ }
+
+ void SetPeer(void* peer) {
+ raw_ptr()->peer_ = peer;
+ }
+
+ 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