static strm_string* str_new(const char *p, size_t len) { strm_string *str; if (readonly_data_p(p)) { str = malloc(sizeof(strm_string)); str->ptr = p; } else { char *buf; str = malloc(sizeof(strm_string)+len+1); buf = (char*)&str[1]; if (p) { memcpy(buf, p, len); } else { memset(buf, 0, len); } buf[len] = '\0'; str->ptr = buf; } str->len = len; str->type = STRM_OBJ_STRING; return str; }
strm_string* strm_str_new(const char *p, size_t len) { if (!strm_event_loop_started) { /* single thread mode */ if (p && (len < STRM_STR_INTERN_LIMIT || readonly_data_p(p))) { return str_intern(p, len); } } return str_new(p, len); }
static strm_string str_new(const char* p, strm_int len, int foreign) { strm_value tag; strm_value val; char* s; if (!p) goto mkbuf; if (len < 6) { tag = STRM_TAG_STRING_I; val = 0; s = VAL_PTR(val)+1; memcpy(s, p, len); s[-1] = len; } else if (len == 6) { tag = STRM_TAG_STRING_6; val = 0; s = VAL_PTR(val); memcpy(s, p, len); } else { struct strm_string* str; if (p && (foreign || readonly_data_p(p))) { tag = STRM_TAG_STRING_F; str = malloc(sizeof(struct strm_string)); str->ptr = p; } else { char *buf; mkbuf: tag = STRM_TAG_STRING_O; str = malloc(sizeof(struct strm_string)+len+1); buf = (char*)&str[1]; if (p) { memcpy(buf, p, len); } else { memset(buf, 0, len); } buf[len] = '\0'; str->ptr = buf; } str->len = len; val = strm_tag_vptr(str, 0); } return tag | (val & STRM_VAL_MASK); }