]> granicus.if.org Git - json-c/commitdiff
json_object_private: save 8 bytes in struct json_object in 64-bit architectures
authorRamiro Polla <ramiro.polla@gmail.com>
Sat, 24 Nov 2018 02:36:51 +0000 (03:36 +0100)
committerRamiro Polla <ramiro.polla@gmail.com>
Sat, 24 Nov 2018 03:16:36 +0000 (04:16 +0100)
- there is no need for _ref_count to be uint_fast32_t (the compiler
  might decide to use a 64-bit int). make it uint32_t instead.
- reorder the 32-bit integer fields (o_type and _ref_count) so that
  there is no wasted 4-byte gap after each of them.

json_object.c
json_object_private.h

index 8a86bc6ea09a5e76995beb54c04b0af0961acfed..3af69fc389ea09ea7347fa5cde5511db4ea2a24e 100644 (file)
@@ -171,7 +171,7 @@ extern struct json_object* json_object_get(struct json_object *jso)
        if (!jso) return jso;
 
        // Don't overflow the refcounter.
-       assert(jso->_ref_count < UINT_FAST32_MAX);
+       assert(jso->_ref_count < UINT32_MAX);
 
 #if defined(HAVE_ATOMIC_BUILTINS) && defined(ENABLE_THREADING)
        __sync_add_and_fetch(&jso->_ref_count, 1);
index 51134b60a298203fb412d45f45d299699cfd4db8..4c6681ae2b5105fbd8d85b444b22d1c3e374d039 100644 (file)
@@ -27,9 +27,9 @@ typedef void (json_object_private_delete_fn)(struct json_object *o);
 struct json_object
 {
   enum json_type o_type;
+  uint32_t _ref_count;
   json_object_private_delete_fn *_delete;
   json_object_to_json_string_fn *_to_json_string;
-  uint_fast32_t _ref_count;
   struct printbuf *_pb;
   union data {
     json_bool c_boolean;