Skip to content

Commit

Permalink
Directly use generate_json_string for object keys
Browse files Browse the repository at this point in the history
... instead of `generate_json`.

Since the object key is already confirmed to be a string, using a
generic dispatch function brings an unnecessary overhead.

This speeds up `JSON.generate` by about 3% in a benchmark.
  • Loading branch information
mame authored and byroot committed Oct 17, 2024
1 parent 4f9180d commit e125072
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ext/json/ext/generator/generator.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include "../fbuffer/fbuffer.h"
#include "generator.h"

#ifndef RB_UNLIKELY
#define RB_UNLIKELY(cond) (cond)
#endif

static VALUE mJSON, mExt, mGenerator, cState, mGeneratorMethods, mObject,
mHash, mArray,
#ifdef RUBY_INTEGER_UNIFICATION
Expand Down Expand Up @@ -678,7 +682,7 @@ json_object_i(VALUE key, VALUE val, VALUE _arg)
break;
}

generate_json(buffer, Vstate, state, key_to_s);
generate_json_string(buffer, Vstate, state, key_to_s);
fbuffer_append(buffer, delim2, delim2_len);
generate_json(buffer, Vstate, state, val);

Expand Down

0 comments on commit e125072

Please sign in to comment.