MCPcopy Create free account
hub / github.com/F-Stack/f-stack / createEmbeddedStringObject

Function createEmbeddedStringObject

app/redis-6.2.6/src/object.c:84–110  ·  view source on GitHub ↗

Create a string object with encoding OBJ_ENCODING_EMBSTR, that is * an object where the sds string is actually an unmodifiable string * allocated in the same chunk as the object itself. */

Source from the content-addressed store, hash-verified

82 * an object where the sds string is actually an unmodifiable string
83 * allocated in the same chunk as the object itself. */
84robj *createEmbeddedStringObject(const char *ptr, size_t len) {
85 robj *o = zmalloc(sizeof(robj)+sizeof(struct sdshdr8)+len+1);
86 struct sdshdr8 *sh = (void*)(o+1);
87
88 o->type = OBJ_STRING;
89 o->encoding = OBJ_ENCODING_EMBSTR;
90 o->ptr = sh+1;
91 o->refcount = 1;
92 if (server.maxmemory_policy & MAXMEMORY_FLAG_LFU) {
93 o->lru = (LFUGetTimeInMinutes()<<8) | LFU_INIT_VAL;
94 } else {
95 o->lru = LRU_CLOCK();
96 }
97
98 sh->len = len;
99 sh->alloc = len;
100 sh->flags = SDS_TYPE_8;
101 if (ptr == SDS_NOINIT)
102 sh->buf[len] = '\0';
103 else if (ptr) {
104 memcpy(sh->buf,ptr,len);
105 sh->buf[len] = '\0';
106 } else {
107 memset(sh->buf,0,len+1);
108 }
109 return o;
110}
111
112/* Create a string object with EMBSTR encoding if it is smaller than
113 * OBJ_ENCODING_EMBSTR_SIZE_LIMIT, otherwise the RAW encoding is

Callers 4

createStringObjectFunction · 0.85
tryCreateStringObjectFunction · 0.85
dupStringObjectFunction · 0.85
tryObjectEncodingFunction · 0.85

Calls 5

zmallocFunction · 0.85
LFUGetTimeInMinutesFunction · 0.85
LRU_CLOCKFunction · 0.85
memsetFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected