@@ -312,7 +312,9 @@ class Json_value_helper
312312/* A common base for Json_writer_object and Json_writer_array */
313313class Json_writer_struct
314314{
315+ #ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
315316 static thread_local std::vector<bool > named_items_expectation;
317+ #endif
316318protected:
317319 Json_writer* my_writer;
318320 Json_value_helper context;
@@ -327,24 +329,30 @@ class Json_writer_struct
327329 my_writer= thd->opt_trace .get_current_json ();
328330 context.init (my_writer);
329331 closed= false ;
332+ #ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
330333 named_items_expectation.push_back (expect_named_children);
334+ #endif
331335 }
332336
333337 virtual ~Json_writer_struct ()
334338 {
339+ #ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
335340 named_items_expectation.pop_back ();
341+ #endif
336342 }
337343
338344 bool trace_started () const
339345 {
340346 return my_writer != 0 ;
341347 }
342348
349+ #ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
343350 bool named_item_expected () const
344351 {
345352 return named_items_expectation.size () > 1
346353 && *(named_items_expectation.rbegin () + 1 );
347354 }
355+ #endif
348356};
349357
350358
@@ -367,15 +375,19 @@ class Json_writer_object : public Json_writer_struct
367375 explicit Json_writer_object (THD *thd)
368376 : Json_writer_struct(thd, true )
369377 {
378+ #ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
370379 DBUG_ASSERT (!named_item_expected ());
380+ #endif
371381 if (unlikely (my_writer))
372382 my_writer->start_object ();
373383 }
374384
375385 explicit Json_writer_object (THD* thd, const char *str)
376386 : Json_writer_struct(thd, true )
377387 {
388+ #ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
378389 DBUG_ASSERT (named_item_expected ());
390+ #endif
379391 if (unlikely (my_writer))
380392 my_writer->add_member (str).start_object ();
381393 }
@@ -542,15 +554,19 @@ class Json_writer_array : public Json_writer_struct
542554 Json_writer_array (THD *thd)
543555 : Json_writer_struct(thd, false )
544556 {
557+ #ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
545558 DBUG_ASSERT (!named_item_expected ());
559+ #endif
546560 if (unlikely (my_writer))
547561 my_writer->start_array ();
548562 }
549563
550564 Json_writer_array (THD *thd, const char *str)
551565 : Json_writer_struct(thd, false )
552566 {
567+ #ifdef ENABLED_JSON_WRITER_CONSISTENCY_CHECKS
553568 DBUG_ASSERT (named_item_expected ());
569+ #endif
554570 if (unlikely (my_writer))
555571 my_writer->add_member (str).start_array ();
556572 }
0 commit comments