This commit is contained in:
blueloveTH 2024-06-02 19:46:18 +08:00
parent f3148ac206
commit e7aababa36
2 changed files with 4 additions and 8 deletions

View File

@ -23,7 +23,7 @@ int utf8len(unsigned char c, bool suppress){
if(this->size < (int)sizeof(this->_inlined)){ \ if(this->size < (int)sizeof(this->_inlined)){ \
this->data = this->_inlined; \ this->data = this->_inlined; \
}else{ \ }else{ \
this->data = (char*)pool128_alloc(this->size+1); \ this->data = (char*)std::malloc(this->size+1); \
} }
#define PK_STR_COPY_INIT(__s) \ #define PK_STR_COPY_INIT(__s) \
@ -103,7 +103,7 @@ int utf8len(unsigned char c, bool suppress){
} }
Str& Str::operator=(const Str& other){ Str& Str::operator=(const Str& other){
if(!is_inlined()) pool128_dealloc(data); if(!is_inlined()) std::free(data);
size = other.size; size = other.size;
is_ascii = other.is_ascii; is_ascii = other.is_ascii;
PK_STR_ALLOCATE() PK_STR_ALLOCATE()
@ -174,7 +174,7 @@ int utf8len(unsigned char c, bool suppress){
} }
Str::~Str(){ Str::~Str(){
if(!is_inlined()) pool128_dealloc(data); if(!is_inlined()) std::free(data);
} }
Str Str::substr(int start, int len) const { Str Str::substr(int start, int len) const {
@ -410,14 +410,10 @@ int utf8len(unsigned char c, bool suppress){
} }
Str SStream::str(){ Str SStream::str(){
#if 0
// after this call, the buffer is no longer valid // after this call, the buffer is no longer valid
buffer.reserve(buffer.size() + 1); // allocate one more byte for '\0' buffer.reserve(buffer.size() + 1); // allocate one more byte for '\0'
buffer[buffer.size()] = '\0'; // set '\0' buffer[buffer.size()] = '\0'; // set '\0'
return Str(buffer.detach()); return Str(buffer.detach());
#else
return Str(buffer.data(), buffer.size());
#endif
} }
SStream& SStream::operator<<(const Str& s){ SStream& SStream::operator<<(const Str& s){

View File

@ -1396,7 +1396,7 @@ __EAT_DOTS_END:
Str TokenDeserializer::read_string_from_hex(char c){ Str TokenDeserializer::read_string_from_hex(char c){
std::string_view s = read_string(c); std::string_view s = read_string(c);
char* buffer = (char*)pool128_alloc(s.size()/2 + 1); char* buffer = (char*)std::malloc(s.size()/2 + 1);
for(int i=0; i<s.size(); i+=2){ for(int i=0; i<s.size(); i+=2){
char c = 0; char c = 0;
if(s[i]>='0' && s[i]<='9') c += s[i]-'0'; if(s[i]>='0' && s[i]<='9') c += s[i]-'0';