@@ -3498,6 +3498,7 @@ class Function : public Object {
3498
3498
FunctionPtr GetMethodExtractor (const String& getter_name) const ;
3499
3499
3500
3500
static bool IsDynamicInvocationForwarderName (const String& name);
3501
+ static bool IsDynamicInvocationForwarderName (StringPtr name);
3501
3502
3502
3503
static StringPtr DemangleDynamicInvocationForwarderName (const String& name);
3503
3504
@@ -8607,7 +8608,10 @@ class String : public Instance {
8607
8608
DISALLOW_IMPLICIT_CONSTRUCTORS (CodePointIterator);
8608
8609
};
8609
8610
8610
- intptr_t Length () const { return Smi::Value (raw_ptr ()->length_ ); }
8611
+ intptr_t Length () const { return LengthOf (raw ()); }
8612
+ static intptr_t LengthOf (StringPtr obj) {
8613
+ return Smi::Value (obj->ptr ()->length_ );
8614
+ }
8611
8615
static intptr_t length_offset () { return OFFSET_OF (StringLayout, length_); }
8612
8616
8613
8617
intptr_t Hash () const {
@@ -8644,7 +8648,8 @@ class String : public Instance {
8644
8648
8645
8649
virtual ObjectPtr HashCode () const { return Integer::New (Hash ()); }
8646
8650
8647
- uint16_t CharAt (intptr_t index) const ;
8651
+ uint16_t CharAt (intptr_t index) const { return CharAt (raw (), index); }
8652
+ static uint16_t CharAt (StringPtr str, intptr_t index);
8648
8653
8649
8654
intptr_t CharSize () const ;
8650
8655
@@ -8682,7 +8687,11 @@ class String : public Instance {
8682
8687
8683
8688
intptr_t CompareTo (const String& other) const ;
8684
8689
8685
- bool StartsWith (const String& other) const ;
8690
+ bool StartsWith (const String& other) const {
8691
+ NoSafepointScope no_safepoint;
8692
+ return StartsWith (raw (), other.raw ());
8693
+ }
8694
+ static bool StartsWith (StringPtr str, StringPtr prefix);
8686
8695
bool EndsWith (const String& other) const ;
8687
8696
8688
8697
// Strings are canonicalized using the symbol table.
@@ -8895,9 +8904,15 @@ class String : public Instance {
8895
8904
class OneByteString : public AllStatic {
8896
8905
public:
8897
8906
static uint16_t CharAt (const String& str, intptr_t index) {
8898
- ASSERT ((index >= 0 ) && (index < str.Length ()));
8899
8907
ASSERT (str.IsOneByteString ());
8900
- return raw_ptr (str)->data ()[index];
8908
+ NoSafepointScope no_safepoint;
8909
+ return OneByteString::CharAt (static_cast <OneByteStringPtr>(str.raw ()),
8910
+ index);
8911
+ }
8912
+
8913
+ static uint16_t CharAt (OneByteStringPtr str, intptr_t index) {
8914
+ ASSERT (index >= 0 && index < String::LengthOf (str));
8915
+ return str->ptr ()->data ()[index];
8901
8916
}
8902
8917
8903
8918
static void SetCharAt (const String& str, intptr_t index, uint8_t code_unit) {
@@ -9037,9 +9052,15 @@ class OneByteString : public AllStatic {
9037
9052
class TwoByteString : public AllStatic {
9038
9053
public:
9039
9054
static uint16_t CharAt (const String& str, intptr_t index) {
9040
- ASSERT ((index >= 0 ) && (index < str.Length ()));
9041
9055
ASSERT (str.IsTwoByteString ());
9042
- return raw_ptr (str)->data ()[index];
9056
+ NoSafepointScope no_safepoint;
9057
+ return TwoByteString::CharAt (static_cast <TwoByteStringPtr>(str.raw ()),
9058
+ index);
9059
+ }
9060
+
9061
+ static uint16_t CharAt (TwoByteStringPtr str, intptr_t index) {
9062
+ ASSERT (index >= 0 && index < String::LengthOf (str));
9063
+ return str->ptr ()->data ()[index];
9043
9064
}
9044
9065
9045
9066
static void SetCharAt (const String& str, intptr_t index, uint16_t ch) {
@@ -9159,8 +9180,15 @@ class TwoByteString : public AllStatic {
9159
9180
class ExternalOneByteString : public AllStatic {
9160
9181
public:
9161
9182
static uint16_t CharAt (const String& str, intptr_t index) {
9183
+ ASSERT (str.IsExternalOneByteString ());
9162
9184
NoSafepointScope no_safepoint;
9163
- return *CharAddr (str, index);
9185
+ return ExternalOneByteString::CharAt (
9186
+ static_cast <ExternalOneByteStringPtr>(str.raw ()), index);
9187
+ }
9188
+
9189
+ static uint16_t CharAt (ExternalOneByteStringPtr str, intptr_t index) {
9190
+ ASSERT (index >= 0 && index < String::LengthOf (str));
9191
+ return str->ptr ()->external_data_ [index];
9164
9192
}
9165
9193
9166
9194
static void * GetPeer (const String& str) { return raw_ptr (str)->peer_ ; }
@@ -9250,8 +9278,15 @@ class ExternalOneByteString : public AllStatic {
9250
9278
class ExternalTwoByteString : public AllStatic {
9251
9279
public:
9252
9280
static uint16_t CharAt (const String& str, intptr_t index) {
9281
+ ASSERT (str.IsExternalTwoByteString ());
9253
9282
NoSafepointScope no_safepoint;
9254
- return *CharAddr (str, index);
9283
+ return ExternalTwoByteString::CharAt (
9284
+ static_cast <ExternalTwoByteStringPtr>(str.raw ()), index);
9285
+ }
9286
+
9287
+ static uint16_t CharAt (ExternalTwoByteStringPtr str, intptr_t index) {
9288
+ ASSERT (index >= 0 && index < String::LengthOf (str));
9289
+ return str->ptr ()->external_data_ [index];
9255
9290
}
9256
9291
9257
9292
static void * GetPeer (const String& str) { return raw_ptr (str)->peer_ ; }
@@ -11202,6 +11237,23 @@ inline void TypeArguments::SetHash(intptr_t value) const {
11202
11237
StoreSmi (&raw_ptr ()->hash_ , Smi::New (value));
11203
11238
}
11204
11239
11240
+ inline uint16_t String::CharAt (StringPtr str, intptr_t index) {
11241
+ switch (str->GetClassId ()) {
11242
+ case kOneByteStringCid :
11243
+ return OneByteString::CharAt (static_cast <OneByteStringPtr>(str), index);
11244
+ case kTwoByteStringCid :
11245
+ return TwoByteString::CharAt (static_cast <TwoByteStringPtr>(str), index);
11246
+ case kExternalOneByteStringCid :
11247
+ return ExternalOneByteString::CharAt (
11248
+ static_cast <ExternalOneByteStringPtr>(str), index);
11249
+ case kExternalTwoByteStringCid :
11250
+ return ExternalTwoByteString::CharAt (
11251
+ static_cast <ExternalTwoByteStringPtr>(str), index);
11252
+ }
11253
+ UNREACHABLE ();
11254
+ return 0 ;
11255
+ }
11256
+
11205
11257
// A view on an [Array] as a list of tuples, optionally starting at an offset.
11206
11258
//
11207
11259
// Example: We store a list of (kind, function, code) tuples into the
0 commit comments