MCPcopy Create free account
hub / github.com/HaxeFoundation/hxcpp / findFixed

Method findFixed

src/hx/Anon.cpp:98–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96#endif
97
98inline int Anon_obj::findFixed(const ::String &inKey, bool inSkip5)
99{
100 if (!mFixedFields || !inKey.isAsciiEncoded() )
101 return -1;
102 VariantKey *fixed = getFixed();
103
104 if (!inSkip5)
105 if (inKey.__s[HX_GC_CONST_ALLOC_MARK_OFFSET] & HX_GC_CONST_ALLOC_MARK_BIT)
106 {
107 for(int i=0;i<mFixedFields;i++)
108 {
109 if (fixed[i].key.__s == inKey.__s)
110 return i;
111 }
112 }
113
114
115 int sought = inKey.hash();
116
117 if (!inSkip5)
118 {
119 if (mFixedFields<5)
120 {
121 for(int i=0;i<mFixedFields;i++)
122 if (fixed[i].hash==sought && (
123 (fixed[i].key.length == inKey.length && !memcmp(fixed[i].key.raw_ptr(),inKey.raw_ptr(), inKey.length))))
124 return i;
125 return -1;
126 }
127 }
128
129 // Find node with same hash...
130 /* hash example
131 [0] = -3 <- min
132 [1] = -1
133 [2] = -1 (sought -1)
134 [3] = 4
135 [4] = 4 <- max
136 */
137
138 int min = inSkip5 ? 5 : 0;
139 if (fixed[min].hash>sought)
140 return -1;
141 if (fixed[min].hash!=sought)
142 {
143 int max = mFixedFields;
144 if (fixed[max-1].hash<sought)
145 return -1;
146
147 while(max>min+1)
148 {
149 int mid = (max+min)>>1;
150 if (fixed[mid].hash <= sought)
151 min = mid;
152 else
153 max = mid;
154 }
155 }

Callers

nothing calls this directly

Calls 2

getFixedFunction · 0.85
memcmpFunction · 0.50

Tested by

no test coverage detected