MCPcopy Create free account
hub / github.com/bytedance/sonic-cpp / StringCopy

Method StringCopy

include/sonic/dom/genericnode.h:197–206  ·  view source on GitHub ↗

* @brief Copy string data to memory allocated from alloc, then store pointer * and size into node. * @param s string pointer * @param len string length * @param alloc Allocator * @note: If failed when allocating memory, the node will be set as an empty * string. */

Source from the content-addressed store, hash-verified

195 * string.
196 */
197 void StringCopy(const char* s, size_t len, alloc_type& alloc) {
198 sv.p = (char*)(alloc.Malloc(len + 1));
199 if (sv.p) {
200 std::memcpy(const_cast<char*>(sv.p), s, len);
201 const_cast<char*>(sv.p)[len] = '\0';
202 setLength(len, kStringFree);
203 } else {
204 setEmptyString();
205 }
206 }
207
208 // Check APIs
209 /**

Callers 1

DNodeMethod · 0.80

Calls 3

setLengthFunction · 0.85
setEmptyStringFunction · 0.85
MallocMethod · 0.45

Tested by

no test coverage detected