| 1090 | } |
| 1091 | |
| 1092 | PB_API const pb_Name *pb_name(const pb_State *S, pb_Slice s, pb_Cache *cache) { |
| 1093 | pb_NameEntry *entry = NULL; |
| 1094 | pb_CacheSlot *slot; |
| 1095 | if (s.p == NULL) return NULL; |
| 1096 | if (cache == NULL) |
| 1097 | entry = pbN_getname(S, s, pbN_calchash(s)); |
| 1098 | else { |
| 1099 | slot = cache->slots[((uintptr_t)s.p*2654435761U)%PB_CACHE_SIZE]; |
| 1100 | if (slot[0].name == s.p) |
| 1101 | entry = pbN_getname(S, s, cache->hash = slot[0].hash); |
| 1102 | else if (slot[1].name == s.p) |
| 1103 | entry = pbN_getname(S, s, cache->hash = (++slot)[0].hash); |
| 1104 | else |
| 1105 | slot[1] = slot[0], slot[0].name = s.p; |
| 1106 | if (entry == NULL) { |
| 1107 | cache->hash = slot[0].hash = pbN_calchash(s); |
| 1108 | entry = pbN_getname(S, s, slot[0].hash); |
| 1109 | } |
| 1110 | } |
| 1111 | return entry ? (pb_Name*)(entry + 1) : NULL; |
| 1112 | } |
| 1113 | |
| 1114 | |
| 1115 | /* state */ |
no test coverage detected