MCPcopy Create free account
hub / github.com/GarageGames/Torque2D / insert

Method insert

engine/source/string/stringTable.cc:121–152  ·  view source on GitHub ↗

--------------------------------------

Source from the content-addressed store, hash-verified

119
120//--------------------------------------
121StringTableEntry _StringTable::insert(const char* val, const bool caseSens)
122{
123 if ( val == NULL )
124 return StringTable->EmptyString;
125
126 MutexHandle mutex;
127 mutex.lock(&mMutex, true);
128
129 Node **walk, *temp;
130 U32 key = hashString(val);
131 walk = &buckets[key % numBuckets];
132 while((temp = *walk) != NULL) {
133 if(caseSens && !dStrcmp(temp->val, val))
134 return temp->val;
135 else if(!caseSens && !dStricmp(temp->val, val))
136 return temp->val;
137 walk = &(temp->next);
138 }
139 char *ret = 0;
140 if(!*walk) {
141 *walk = (Node *) mempool.alloc(sizeof(Node));
142 (*walk)->next = 0;
143 (*walk)->val = (char *) mempool.alloc(dStrlen(val) + 1);
144 dStrcpy((*walk)->val, val);
145 ret = (*walk)->val;
146 itemCount ++;
147 }
148 if(itemCount > 2 * numBuckets) {
149 resize(4 * numBuckets - 1);
150 }
151 return ret;
152}
153
154//--------------------------------------
155StringTableEntry _StringTable::insertn(const char* src, S32 len, const bool caseSens)

Callers 2

getSTValueMethod · 0.45
getStringTableUnitFunction · 0.45

Calls 6

dStrlenFunction · 0.70
dStrcmpFunction · 0.50
dStricmpFunction · 0.50
dStrcpyFunction · 0.50
lockMethod · 0.45
allocMethod · 0.45

Tested by

no test coverage detected