MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / insert

Method insert

Engine/source/console/simDictionary.cpp:48–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46}
47
48void SimNameDictionary::insert(SimObject* obj)
49{
50 if (!obj || !obj->getName())
51 return;
52
53 SimObject* checkForDup = find(obj->getName());
54
55 if (checkForDup)
56 Con::warnf("Warning! You have a duplicate object name of %s. This can cause problems. You should rename one of them.", obj->getName());
57
58 Mutex::lockMutex(mutex);
59#ifndef USE_NEW_SIMDICTIONARY
60 if (!hashTable)
61 {
62 hashTable = new SimObject *[DefaultTableSize];
63 hashTableSize = DefaultTableSize;
64 hashEntryCount = 0;
65
66 dMemset(hashTable, 0, sizeof(*hashTable) * DefaultTableSize);
67 }
68
69 S32 idx = HashPointer(obj->getName()) % hashTableSize;
70 obj->nextNameObject = hashTable[idx];
71 hashTable[idx] = obj;
72 hashEntryCount++;
73
74 // Rehash if necessary.
75
76 if (hashEntryCount > hashTableSize)
77 {
78 // Allocate new table.
79
80 U32 newHashTableSize = hashTableSize * 2 + 1;
81 SimObject** newHashTable = new SimObject *[newHashTableSize];
82 dMemset(newHashTable, 0, sizeof(newHashTable[0]) * newHashTableSize);
83
84 // Move entries over.
85
86 for (U32 i = 0; i < hashTableSize; ++i)
87 for (SimObject* object = hashTable[i]; object != NULL; )
88 {
89 SimObject* next = object->nextNameObject;
90
91 idx = HashPointer(object->getName()) % newHashTableSize;
92 object->nextNameObject = newHashTable[idx];
93 newHashTable[idx] = object;
94
95 object = next;
96 }
97
98 // Switch tables.
99
100 delete[] hashTable;
101 hashTable = newHashTable;
102 hashTableSize = newHashTableSize;
103 }
104#else
105 root[obj->objectName] = obj;

Callers

nothing calls this directly

Calls 6

HashPointerFunction · 0.85
warnfFunction · 0.70
getIdMethod · 0.65
findFunction · 0.50
dMemsetFunction · 0.50
getNameMethod · 0.45

Tested by

no test coverage detected