File tree 2 files changed +11
-3
lines changed
2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -16,15 +16,20 @@ Utf8Value::Utf8Value(v8::Isolate* isolate, v8::Handle<v8::Value> value)
16
16
// Allocate enough space to include the null terminator
17
17
size_t len = StringBytes::StorageSize (val_, UTF8) + 1 ;
18
18
19
- char * str = static_cast <char *>(calloc (1 , len));
19
+ char * str;
20
+ if (len > kStorageSize )
21
+ str = static_cast <char *>(malloc (len));
22
+ else
23
+ str = str_st_;
24
+ CHECK_NE (str, NULL );
20
25
21
26
int flags = WRITE_UTF8_FLAGS;
22
- flags |= ~v8::String::NO_NULL_TERMINATION;
23
27
24
28
length_ = val_->WriteUtf8 (str,
25
29
len,
26
30
0 ,
27
31
flags);
32
+ str[length_] = ' \0 ' ;
28
33
29
34
str_ = reinterpret_cast <char *>(str);
30
35
}
Original file line number Diff line number Diff line change @@ -110,7 +110,8 @@ class Utf8Value {
110
110
explicit Utf8Value (v8::Isolate* isolate, v8::Handle <v8::Value> value);
111
111
112
112
~Utf8Value () {
113
- free (str_);
113
+ if (str_ != str_st_)
114
+ free (str_);
114
115
}
115
116
116
117
char * operator *() {
@@ -126,7 +127,9 @@ class Utf8Value {
126
127
};
127
128
128
129
private:
130
+ static const int kStorageSize = 1024 ;
129
131
size_t length_;
132
+ char str_st_[kStorageSize ];
130
133
char * str_;
131
134
};
132
135
You can’t perform that action at this time.
0 commit comments