Ignore:
Timestamp:
Dec 15, 2012, 12:01:59 AM (9 years ago)
Author:
jordan
Message:

(trunk, libT) faster JSON parsing for tr_variant. This mostly helps the Qt client, which makes heavy use of the JSON-based RPC calls.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/variant.c

    r13669 r13672  
    8989  if (tr_variantIsDict (dict))
    9090    {
    91       size_t i;
     91      const tr_variant * walk;
     92      const tr_variant * const begin = dict->val.l.vals;
     93      const tr_variant * const end = begin + dict->val.l.count;
    9294      const size_t len = strlen (key);
    9395
    94       for (i=0; (i+1) < dict->val.l.count; i += 2)
    95         {
    96           const tr_variant * child = dict->val.l.vals + i;
    97           if ((child->type == TR_VARIANT_TYPE_STR)
    98               && (child->val.s.len == len)
    99               && !memcmp (getStr (child), key, len))
    100             return i;
    101         }
     96      for (walk=begin; walk!=end; walk+=2)
     97      {
     98        assert (walk->type == TR_VARIANT_TYPE_STR);
     99
     100        if ((walk->val.s.len==len) && !memcmp (getStr(walk), key, len))
     101          return walk - begin;
     102      }
    102103    }
    103104
     
    528529tr_variant *
    529530tr_variantDictAdd (tr_variant  * dict,
    530                    const char  * key)
     531                   const char  * key,
     532                   int           keylen)
    531533{
    532534  tr_variant * child_key;
     
    538540
    539541  child_key = dict->val.l.vals + dict->val.l.count++;
    540   tr_variantInitStr (child_key, key, -1);
     542  tr_variantInitStr (child_key, key, keylen);
    541543
    542544  child_val = dict->val.l.vals + dict->val.l.count++;
     
    562564  /* if it doesn't exist, create it */
    563565  if (child == NULL)
    564     child = tr_variantDictAdd (dict, key);
     566    child = tr_variantDictAdd (dict, key, -1);
    565567
    566568  return child;
     
    615617  /* if it doesn't exist, create it */
    616618  if (child == NULL)
    617     child = tr_variantDictAdd (dict, key);
     619    child = tr_variantDictAdd (dict, key, -1);
    618620
    619621  return child;
     
    645647                       size_t       reserve_count)
    646648{
    647   tr_variant * child = tr_variantDictAdd (dict, key);
     649  tr_variant * child = tr_variantDictAdd (dict, key, -1);
    648650  tr_variantInitList (child, reserve_count);
    649651  return child;
     
    655657                       size_t       reserve_count)
    656658{
    657   tr_variant * child = tr_variantDictAdd (dict, key);
     659  tr_variant * child = tr_variantDictAdd (dict, key, -1);
    658660  tr_variantInitDict (child, reserve_count);
    659661  return child;
Note: See TracChangeset for help on using the changeset viewer.