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

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: pre-review clean-up 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..d947cf941a0c96807ab5b7c283a8eba6ffc0088b 100644
--- a/runtime/vm/object.h
+++ b/runtime/vm/object.h
@@ -2365,6 +2365,18 @@ class String : public Instance {
static intptr_t Hash(const uint16_t* characters, intptr_t len);
static intptr_t Hash(const uint32_t* characters, intptr_t len);
+ bool HasOneByteChar() const {
+ return IsOneByteString() || IsExternalOneByteString();
+ }
+
+ bool HasTwoByteChar() const {
+ return IsTwoByteString() || IsExternalTwoByteString();
+ }
+
+ bool HasFourByteChar() const {
+ return IsFourByteString() || IsExternalFourByteString();
+ }
turnidge 2011/10/25 18:07:20 Passing thought... Would it make sense to add a vi
cshapiro 2011/10/25 20:42:47 Sounds like a good idea. This will show up in my
+
virtual int32_t CharAt(intptr_t index) const;
bool Equals(const String& str, intptr_t begin_index, intptr_t len) const;
@@ -2502,11 +2514,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);
@@ -2557,11 +2564,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);
@@ -2608,11 +2610,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 +2626,108 @@ class FourByteString : public String {
};
+class ExternalOneByteString : public String {
+ public:
+ typedef void (*Finalizer)(uint8_t* characters);
+
+ virtual int32_t CharAt(intptr_t index) const {
+ return *CharAddr(index);
+ }
+
+ static intptr_t InstanceSize() {
+ return RoundedAllocationSize(sizeof(RawExternalOneByteString));
+ }
+
+ static RawExternalOneByteString* New(const uint8_t* characters,
+ intptr_t len,
+ Finalizer finalizer,
+ Heap::Space space = Heap::kNew);
+
+ 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);
+ }
+
+ HEAP_OBJECT_IMPLEMENTATION(ExternalOneByteString, String);
+ friend class Class;
+ friend class String;
+};
+
+
+class ExternalTwoByteString : public String {
+ public:
+ typedef void (*Finalizer)(uint16_t* characters);
+
+ virtual int32_t CharAt(intptr_t index) const {
+ return *CharAddr(index);
+ }
+
+ static intptr_t InstanceSize() {
+ return RoundedAllocationSize(sizeof(RawExternalTwoByteString));
+ }
+
+ static RawExternalTwoByteString* New(const uint16_t* characters,
+ intptr_t len,
+ Finalizer finalizer,
+ 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);
+ }
+
+ HEAP_OBJECT_IMPLEMENTATION(ExternalTwoByteString, String);
+ friend class Class;
+ friend class String;
+};
+
+
+class ExternalFourByteString : public String {
+ public:
+ typedef void (*Finalizer)(uint32_t* characters);
+
+ virtual int32_t CharAt(intptr_t index) const {
+ return *CharAddr(index);
+ }
+
+ static intptr_t InstanceSize() {
+ return RoundedAllocationSize(sizeof(RawExternalFourByteString));
+ }
+
+ static RawExternalFourByteString* New(const uint32_t* characters,
+ intptr_t len,
+ Finalizer finalizer,
+ 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);
+ }
+
+ 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