File tree 5 files changed +37
-45
lines changed
5 files changed +37
-45
lines changed Original file line number Diff line number Diff line change 29
29
#include < cctype>
30
30
#include < cstdint>
31
31
#include < cstdio>
32
+ #include < cstring>
32
33
#include < string>
33
34
34
35
#include " ../misc/defs.h"
@@ -74,7 +75,7 @@ static vm_oop_t strLength(vm_oop_t rcvr) {
74
75
}
75
76
76
77
static vm_oop_t strEqual (vm_oop_t leftObj, vm_oop_t op1) {
77
- VMString* op2 = static_cast <VMString*>(leftObj);
78
+ VMString* left = static_cast <VMString*>(leftObj);
78
79
79
80
if (IS_TAGGED (op1)) {
80
81
return load_ptr (falseObject);
@@ -85,14 +86,18 @@ static vm_oop_t strEqual(vm_oop_t leftObj, vm_oop_t op1) {
85
86
}
86
87
87
88
VMClass* otherClass = CLASS_OF (op1);
88
- if (otherClass == load_ptr (stringClass) ||
89
- otherClass = = load_ptr (symbolClass)) {
90
- StdString s1 = static_cast <VMString*>(op1)-> GetStdString ( );
91
- StdString s2 = op2-> GetStdString ();
89
+ if (otherClass != load_ptr (stringClass) &&
90
+ otherClass ! = load_ptr (symbolClass)) {
91
+ return load_ptr (falseObject );
92
+ }
92
93
93
- if (s1 == s2) {
94
- return load_ptr (trueObject);
95
- }
94
+ VMString* right = static_cast <VMString*>(op1);
95
+ if (left->length != right->length ) {
96
+ return load_ptr (falseObject);
97
+ }
98
+
99
+ if (strncmp (left->chars , right->chars , left->length ) == 0 ) {
100
+ return load_ptr (trueObject);
96
101
}
97
102
return load_ptr (falseObject);
98
103
}
Original file line number Diff line number Diff line change 40
40
41
41
const size_t VMArray::VMArrayNumberOfFields = 0 ;
42
42
43
- VMArray::VMArray (size_t arraySize, size_t additionalBytes)
44
- : VMObject(
45
- arraySize + 0 /* VMArray is not allowed to have any fields itself */ ,
46
- additionalBytes + sizeof (VMArray)) {
47
- assert (VMArrayNumberOfFields == 0 );
48
- nilInitializeFields ();
49
- }
50
-
51
43
VMArray* VMArray::Copy () const {
52
44
VMArray* copy = Universe::NewArray (GetNumberOfIndexableFields ());
53
45
Original file line number Diff line number Diff line change @@ -39,7 +39,12 @@ class VMArray : public VMObject {
39
39
public:
40
40
typedef GCArray Stored;
41
41
42
- explicit VMArray (size_t arraySize, size_t additionalBytes);
42
+ explicit VMArray (size_t arraySize, size_t additionalBytes)
43
+ : VMObject(arraySize +
44
+ 0 /* VMArray is not allowed to have any fields itself */ ,
45
+ additionalBytes + sizeof (VMArray)) {
46
+ assert (VMArrayNumberOfFields == 0 );
47
+ }
43
48
44
49
// VMArray doesn't need to customize `void WalkObjects(walk_heap_fn)`,
45
50
// because it doesn't need anything special.
Original file line number Diff line number Diff line change @@ -43,21 +43,6 @@ VMString* VMString::CloneForMovingGC() const {
43
43
VMString (length, chars);
44
44
}
45
45
46
- void VMString::MarkObjectAsInvalid () {
47
- for (size_t i = 0 ; i < length; i++) {
48
- chars[i] = ' z' ;
49
- }
50
- chars = (char *)INVALID_GC_POINTER;
51
- }
52
-
53
- bool VMString::IsMarkedInvalid () const {
54
- return chars == (char *)INVALID_GC_POINTER;
55
- }
56
-
57
- void VMString::WalkObjects (walk_heap_fn) {
58
- // nothing to do
59
- }
60
-
61
46
size_t VMString::GetObjectSize () const {
62
47
size_t size = sizeof (VMString) + PADDED_SIZE (length);
63
48
return size;
@@ -67,10 +52,6 @@ VMClass* VMString::GetClass() const {
67
52
return load_ptr (stringClass);
68
53
}
69
54
70
- size_t VMString::GetStringLength () const {
71
- return length;
72
- }
73
-
74
55
std::string VMString::GetStdString () const {
75
56
if (chars == 0 ) {
76
57
return std::string (" " );
Original file line number Diff line number Diff line change @@ -52,17 +52,30 @@ class VMString : public AbstractVMObject {
52
52
return (int64_t )hash;
53
53
}
54
54
55
- inline char * GetRawChars () const ;
55
+ inline char * GetRawChars () const { return chars; }
56
+
56
57
StdString GetStdString () const ;
57
- size_t GetStringLength () const ;
58
+
59
+ inline size_t GetStringLength () const { return length; }
58
60
59
61
VMString* CloneForMovingGC () const override ;
60
62
VMClass* GetClass () const override ;
61
63
size_t GetObjectSize () const override ;
62
- void WalkObjects (walk_heap_fn) override ;
63
64
64
- void MarkObjectAsInvalid () override ;
65
- bool IsMarkedInvalid () const override ;
65
+ inline void WalkObjects (walk_heap_fn) override {
66
+ // nothing to do
67
+ }
68
+
69
+ void MarkObjectAsInvalid () override {
70
+ for (size_t i = 0 ; i < length; i++) {
71
+ chars[i] = ' z' ;
72
+ }
73
+ chars = (char *)INVALID_GC_POINTER;
74
+ }
75
+
76
+ bool IsMarkedInvalid () const override {
77
+ return chars == (char *)INVALID_GC_POINTER;
78
+ }
66
79
67
80
StdString AsDebugString () const override ;
68
81
@@ -80,7 +93,3 @@ class VMString : public AbstractVMObject {
80
93
length(length),
81
94
chars(adaptedCharsPointer) {}; // constructor to use by VMSymbol
82
95
};
83
-
84
- char * VMString::GetRawChars () const {
85
- return chars;
86
- }
You can’t perform that action at this time.
0 commit comments