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

Method CreateMap

include/sonic/dom/dynamicnode.h:277–294  ·  view source on GitHub ↗

* @brief Create a map to trace all members of this object. * @param alloc allocator that maintain this node's memory * @retval true successful * @retval false failed, which means that no memory can be allocated by * allocator. */

Source from the content-addressed store, hash-verified

275 * allocator.
276 */
277 bool CreateMap(Allocator& alloc) {
278 sonic_assert(this->IsObject());
279 sonic_assert(this->Capacity() >= this->Size());
280 // if (this->Size() == 0) return false;
281 if (nullptr == children()) {
282 this->memberReserveImpl(16, alloc);
283 }
284 if (getMapUnsfe()) return true;
285 map_type* map = static_cast<map_type*>(alloc.Malloc(sizeof(map_type)));
286 new (map) map_type(MAType(&alloc));
287 // SetMap(map);
288 MemberNode* m = (MemberNode*)getObjChildrenFirstUnsafe();
289 for (size_t i = 0; i < this->Size(); ++i) {
290 map->emplace(std::make_pair((m + i)->name.GetStringView(), i));
291 }
292 setMap(map);
293 return true;
294 }
295
296 /**
297 * @brief Destory the created map. This means that you don't want maintain the

Callers 3

mainFunction · 0.80
TYPED_TESTFunction · 0.80
UpdateNodeLazyFunction · 0.80

Calls 4

IsObjectMethod · 0.80
CapacityMethod · 0.45
SizeMethod · 0.45
MallocMethod · 0.45

Tested by 1

TYPED_TESTFunction · 0.64