@@ -2152,7 +2152,7 @@ bool Json_dom::seek(const Json_seekable_path &path,
2152
2152
auto-wrapping. Those paths can take advantage of the efficient
2153
2153
positioning logic of json_binary::Value.
2154
2154
2155
- @param[in] wrapper the wrapper to search
2155
+ @param[in] value the JSON value to search
2156
2156
@param[in] current_leg iterator to the first path leg to look at.
2157
2157
Usually called on the root document with an iterator pointing to
2158
2158
the beginning of the path, and then incremented in recursive calls
@@ -2165,143 +2165,106 @@ bool Json_dom::seek(const Json_seekable_path &path,
2165
2165
2166
2166
@returns false if there was no error, otherwise true on error
2167
2167
*/
2168
- static bool seek_no_dup_elimination (const Json_wrapper &wrapper ,
2168
+ static bool seek_no_dup_elimination (const json_binary::Value &value ,
2169
2169
const Json_path_iterator ¤t_leg,
2170
2170
const Json_path_iterator &last_leg,
2171
2171
Json_wrapper_vector *hits,
2172
2172
bool auto_wrap,
2173
2173
bool only_need_one)
2174
2174
{
2175
- // DOMs are searched using Json_dom::seek() instead.
2176
- DBUG_ASSERT (!wrapper.is_dom ());
2177
-
2178
2175
if (current_leg == last_leg)
2179
- return hits->push_back (wrapper );
2176
+ return hits->emplace_back (value );
2180
2177
2181
2178
const Json_path_leg *path_leg= *current_leg;
2182
2179
const Json_path_iterator next_leg= current_leg + 1 ;
2183
- const enum_json_type jtype= wrapper.type ();
2184
2180
2185
2181
switch (path_leg->get_type ())
2186
2182
{
2187
2183
case jpl_member:
2188
2184
{
2189
- switch (jtype)
2190
- {
2191
- case enum_json_type::J_OBJECT:
2192
- {
2193
- Json_wrapper member= wrapper.lookup (path_leg->get_member_name ());
2194
-
2195
- if (member.type () != enum_json_type::J_ERROR)
2196
- {
2197
- // recursion
2198
- if (seek_no_dup_elimination (member, next_leg, last_leg, hits,
2199
- auto_wrap, only_need_one))
2200
- return true ; /* purecov: inspected */
2201
- }
2202
- return false ;
2203
- }
2185
+ if (!value.is_object ())
2186
+ return false ;
2204
2187
2205
- default :
2206
- {
2207
- return false ;
2208
- }
2209
- } // end inner switch on wrapper type
2188
+ json_binary::Value member= value.lookup (path_leg->get_member_name ());
2189
+ if (member.type () == json_binary::Value::ERROR)
2190
+ return false ;
2191
+
2192
+ // recursion
2193
+ return seek_no_dup_elimination (member, next_leg, last_leg, hits,
2194
+ auto_wrap, only_need_one);
2210
2195
}
2211
2196
2212
2197
case jpl_member_wildcard:
2198
+ if (!value.is_object ())
2199
+ return false ;
2200
+
2201
+ for (size_t i= 0 , size= value.element_count (); i < size; ++i)
2213
2202
{
2214
- switch (jtype)
2215
- {
2216
- case enum_json_type::J_OBJECT:
2217
- {
2218
- for (Json_wrapper_object_iterator iter= wrapper.object_iterator ();
2219
- !iter.empty (); iter.next ())
2220
- {
2221
- if (is_seek_done (hits, only_need_one))
2222
- return false ;
2223
-
2224
- // recursion
2225
- if (seek_no_dup_elimination (iter.elt ().second , next_leg, last_leg,
2226
- hits, auto_wrap, only_need_one))
2227
- return true ; /* purecov: inspected */
2228
- }
2229
- return false ;
2230
- }
2203
+ if (is_seek_done (hits, only_need_one))
2204
+ return false ;
2231
2205
2232
- default :
2233
- {
2234
- return false ;
2235
- }
2236
- } // end inner switch on wrapper type
2206
+ // recursion
2207
+ if (seek_no_dup_elimination (value.element (i), next_leg, last_leg,
2208
+ hits, auto_wrap, only_need_one))
2209
+ return true ; /* purecov: inspected */
2237
2210
}
2238
2211
2212
+ return false ;
2213
+
2239
2214
case jpl_array_cell:
2240
- if (jtype == enum_json_type::J_ARRAY )
2215
+ if (value. is_array () )
2241
2216
{
2242
- const Json_array_index idx= path_leg->first_array_index (wrapper.length ());
2217
+ const Json_array_index idx=
2218
+ path_leg->first_array_index (value.element_count ());
2243
2219
return idx.within_bounds () &&
2244
- seek_no_dup_elimination (wrapper[ idx.position ()] , next_leg, last_leg, hits ,
2245
- auto_wrap, only_need_one);
2220
+ seek_no_dup_elimination (value. element ( idx.position ()) , next_leg,
2221
+ last_leg, hits, auto_wrap, only_need_one);
2246
2222
}
2247
2223
return auto_wrap && path_leg->is_autowrap () &&
2248
- seek_no_dup_elimination (wrapper , next_leg, last_leg, hits,
2224
+ seek_no_dup_elimination (value , next_leg, last_leg, hits,
2249
2225
auto_wrap, only_need_one);
2250
2226
2251
2227
case jpl_array_range:
2252
2228
case jpl_array_cell_wildcard:
2253
- if (jtype == enum_json_type::J_ARRAY )
2229
+ if (value. is_array () )
2254
2230
{
2255
- const auto range= path_leg->get_array_range (wrapper. length ());
2256
- for (size_t idx = range.m_begin ; idx < range.m_end ; idx++ )
2231
+ const auto range= path_leg->get_array_range (value. element_count ());
2232
+ for (size_t i = range.m_begin ; i < range.m_end ; ++i )
2257
2233
{
2258
2234
if (is_seek_done (hits, only_need_one))
2259
2235
return false ;
2260
2236
2261
2237
// recursion
2262
- if (seek_no_dup_elimination (wrapper[idx] , next_leg, last_leg, hits,
2238
+ if (seek_no_dup_elimination (value. element (i) , next_leg, last_leg, hits,
2263
2239
auto_wrap, only_need_one))
2264
2240
return true ; /* purecov: inspected */
2265
2241
}
2266
2242
return false ;
2267
2243
}
2268
2244
return auto_wrap && path_leg->is_autowrap () &&
2269
- seek_no_dup_elimination (wrapper , next_leg, last_leg, hits,
2245
+ seek_no_dup_elimination (value , next_leg, last_leg, hits,
2270
2246
auto_wrap, only_need_one);
2271
2247
2272
2248
case jpl_ellipsis:
2273
2249
// recursion
2274
- if (seek_no_dup_elimination (wrapper , next_leg, last_leg, hits,
2250
+ if (seek_no_dup_elimination (value , next_leg, last_leg, hits,
2275
2251
auto_wrap, only_need_one))
2276
2252
return true ; /* purecov: inspected */
2277
- if (jtype == enum_json_type::J_ARRAY)
2278
- {
2279
- const size_t length= wrapper.length ();
2280
- for (size_t idx= 0 ; idx < length; ++idx)
2281
- {
2282
- if (is_seek_done (hits, only_need_one))
2283
- return false ;
2284
2253
2285
- // recursion
2286
- if (seek_no_dup_elimination (wrapper[idx], current_leg, last_leg, hits,
2287
- auto_wrap, only_need_one))
2288
- return true ; /* purecov: inspected */
2289
- }
2290
- }
2291
- else if (jtype == enum_json_type::J_OBJECT)
2254
+ if (value.is_array () || value.is_object ())
2292
2255
{
2293
- for (Json_wrapper_object_iterator iter= wrapper.object_iterator ();
2294
- !iter.empty (); iter.next ())
2256
+ for (size_t i= 0 , size= value.element_count (); i < size; ++i)
2295
2257
{
2296
2258
if (is_seek_done (hits, only_need_one))
2297
2259
return false ;
2298
2260
2299
2261
// recursion
2300
- if (seek_no_dup_elimination (iter. elt (). second , current_leg, last_leg,
2262
+ if (seek_no_dup_elimination (value. element (i) , current_leg, last_leg,
2301
2263
hits, auto_wrap, only_need_one))
2302
2264
return true ; /* purecov: inspected */
2303
2265
}
2304
2266
}
2267
+
2305
2268
return false ;
2306
2269
} // end outer switch on leg type
2307
2270
@@ -2343,7 +2306,7 @@ bool Json_wrapper::seek(const Json_seekable_path &path,
2343
2306
return false ;
2344
2307
}
2345
2308
2346
- return seek_no_dup_elimination (* this , path.begin (), path.end (), hits,
2309
+ return seek_no_dup_elimination (m_value , path.begin (), path.end (), hits,
2347
2310
auto_wrap, only_need_one);
2348
2311
}
2349
2312
@@ -3719,7 +3682,7 @@ bool Json_wrapper::attempt_binary_update(const Field_json *field,
3719
3682
3720
3683
// Find the parent of the value we want to modify.
3721
3684
Json_wrapper_vector hits (key_memory_JSON);
3722
- if (seek_no_dup_elimination (* this , path.begin (), path.end () - 1 , &hits,
3685
+ if (seek_no_dup_elimination (m_value , path.begin (), path.end () - 1 , &hits,
3723
3686
false , true ))
3724
3687
return true ; /* purecov: inspected */
3725
3688
@@ -3865,7 +3828,7 @@ bool Json_wrapper::binary_remove(const Field_json *field,
3865
3828
*found_path= false ;
3866
3829
3867
3830
Json_wrapper_vector hits (key_memory_JSON);
3868
- if (seek_no_dup_elimination (* this , path.begin (), path.end () - 1 , &hits,
3831
+ if (seek_no_dup_elimination (m_value , path.begin (), path.end () - 1 , &hits,
3869
3832
false , true ))
3870
3833
return true ; /* purecov: inspected */
3871
3834
0 commit comments