MCPcopy Create free account
hub / github.com/bytedance/Fastbot_Android / CreateSharedString

Function CreateSharedString

native/thirdpart/flatbuffers/flatbuffers.h:1608–1625  ·  view source on GitHub ↗

@brief Store a string in the buffer, which can contain any binary data. If a string with this exact contents has already been serialized before, instead simply returns the offset of the existing string. @param[in] str A const char pointer to the data to be stored as a string. @param[in] len The number of bytes that should be stored from `str`. @return Returns the offset in the buffer where the str

Source from the content-addressed store, hash-verified

1606 /// @param[in] len The number of bytes that should be stored from `str`.
1607 /// @return Returns the offset in the buffer where the string starts.
1608 Offset<String> CreateSharedString(const char *str, size_t len) {
1609 if (!string_pool)
1610 string_pool = new StringOffsetMap(StringOffsetCompare(buf_));
1611 auto size_before_string = buf_.size();
1612 // Must first serialize the string, since the set is all offsets into
1613 // buffer.
1614 auto off = CreateString(str, len);
1615 auto it = string_pool->find(off);
1616 // If it exists we reuse existing serialized data!
1617 if (it != string_pool->end()) {
1618 // We can remove the string we serialized.
1619 buf_.pop(buf_.size() - size_before_string);
1620 return *it;
1621 }
1622 // Record this string for future use.
1623 string_pool->insert(off);
1624 return off;
1625 }
1626
1627#ifdef FLATBUFFERS_HAS_STRING_VIEW
1628 /// @brief Store a string in the buffer, which can contain any binary data.

Callers

nothing calls this directly

Calls 7

CreateStringFunction · 0.85
lengthMethod · 0.80
StringOffsetCompareClass · 0.70
sizeMethod · 0.45
endMethod · 0.45
dataMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected