DLLEXPORT(void) unUseStr(const char *s) { StrItem *t, *p; unsigned int h = hashStr(s); if ((t = strTbl[h]) != 0) { p = t; do { if (qstricmp(t->s,s) == 0) { t->refCnt--; if (t->refCnt == 0) { if (p == strTbl[h]) { strTbl[h] = t->next; } else { p->next = t->next; } deleteStr(t->s); deleteStrItem(t); return; } } p = t; t = t->next; } while (t); } }
void unUseStr(const char *s) { StrItem *cur, *prev; unsigned int h = hashStr(s); cur = strTbl[h]; prev = cur; while (cur != 0) { if (strcasecmp(cur->s,s) == 0) { cur->refCnt--; /* if that was the last reference to this string, kill it. */ if (cur->refCnt == 0) { if (cur == strTbl[h]) { strTbl[h] = cur->next; deleteStr(prev->s); deleteStrItem(prev); } else { prev->next = cur->next; deleteStr(cur->s); deleteStrItem(cur); } return; } } prev = cur; cur = cur->next; } }
void unUseStr(const char *s) { StrItem *t, *p; unsigned int h = hashStr(s); if ((t = strTbl[h]) != 0) { p = t; do { if (PL_strcasecmp(t->s,s) == 0) { t->refCnt--; if (t->refCnt == 0) { if (t == strTbl[h]) { strTbl[h] = t->next; } else { p->next = t->next; } deleteString((char *)t->s); deleteStrItem(t); return; } } p = t; t = t->next; } while (t); } }
uint32_t insertSymbol(string_t *name, symtab_t *symbols, bool scoped) { uint64_t hash = hashStr(name->val, name->len); value_t symName, symTab; symbol_t *sym; symName.bits = vt_string; symName.addr = name; symTab.bits = vt_object; symTab.oval = &symbols->entries; if (!symbols) symbols = &globalSymbols; if (hoistDebug) printf("insertSymbol('%.*s')\n", name->len, name->val); if ((sym = findSymbol(symTab, symName, true, hash))) { sym->frameIdx = ++symbols->frameIdx; sym->depth = symbols->depth; sym->scoped = scoped; return sym->frameIdx; } return 0; }
// Hash an element (usually a custom element), for the purposes of identifying later unsigned long hashElement(struct Element* element) { //Stringify the element char* stringified = stringifyElement(element); unsigned long hash = hashStr(stringified); free(stringified); return hash; }
DLLEXPORT(const char*) lookupStr(const char *s) { StrItem *t; unsigned int h = hashStr(s); if ((t = strTbl[h]) != 0) { do { if (qstricmp(t->s,s) == 0) { t->refCnt++; return t->s; } t = t->next; } while (t); } s = dupStr(s,0); strTbl[h] = newStrItem(s,strTbl[h]); return s; }
const char* lookupStr(const char *s) { char *newS; StrItem *t; unsigned int h = hashStr(s); if ((t = strTbl[h]) != 0) { do { if (strcasecmp(t->s,s) == 0) { t->refCnt++; return t->s; } t = t->next; } while (t); } newS = dupStr(s,0); strTbl[h] = newStrItem(newS,strTbl[h]); return newS; }
symbol_t *lookupSymbol(string_t *name, symtab_t *symbols, symtab_t *block) { uint64_t hash = hashStr(name->val, name->len); value_t symName, symTab; symbol_t *sym; symName.bits = vt_string; symName.addr = name; symTab.bits = vt_object; if (hoistDebug) printf("lookupSymbol('%.*s')\n", name->len, name->val); while (block) { symTab.oval = &block->entries; if ((sym = findSymbol(symTab, symName, false, hash))) { if (!sym->fixed) { if (block->parent) sym->frameIdx += block->parent->frameIdx + block->parent->baseIdx; else sym->frameIdx += symbols->frameIdx; sym->fixed = 1; } return sym; } else block = block->parent; } while (symbols) { symTab.oval = &symbols->entries; if ((sym = findSymbol(symTab, symName, false, hash))) return sym; else symbols = symbols->parent; } return NULL; }
inline std::string passwordHash( const std::string &name, const std::string &password ) { return hashStr(name + ':' + password); }
inline std::string saltedHash( const std::string &value, const std::string &salt ) { return hashStr(value + salt); }