Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f3f3fba

Browse files
author
Nikita Glukhov
committed
Remove JsonPath typedef, rename JsonPathXxx() functions
1 parent c3bdecd commit f3f3fba

File tree

1 file changed

+13
-28
lines changed

1 file changed

+13
-28
lines changed

src/backend/utils/adt/jsonb_typanalyze.c

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,13 @@ typedef struct JsonPathEntry JsonPathEntry;
8181
* XXX We need entry+lenth because JSON path elements may contain null
8282
* bytes, I guess?
8383
*/
84-
struct JsonPathEntry
84+
typedef struct JsonPathEntry
8585
{
8686
JsonPathEntry *parent;
8787
const char *entry; /* element of the path as a string */
8888
int len; /* length of entry string (may be 0) */
8989
uint32 hash; /* hash of the whole path (with parent) */
90-
};
91-
92-
/*
93-
* A path is simply a pointer to the last element (we can traverse to
94-
* the top easily).
95-
*/
96-
typedef JsonPathEntry *JsonPath;
90+
} JsonPathEntry;
9791

9892
/* An array containing a dynamic number of JSON values. */
9993
typedef struct JsonValues
@@ -191,12 +185,9 @@ typedef struct JsonAnalyzeContext
191185
*
192186
* Returned int instead of bool, because it is an implementation of
193187
* HashCompareFunc.
194-
*
195-
* XXX Sould be JsonPathEntryMatch as it deals with JsonPathEntry nodes
196-
* not whole paths, no?
197188
*/
198189
static int
199-
JsonPathMatch(const void *key1, const void *key2, Size keysize)
190+
JsonPathEntryMatch(const void *key1, const void *key2, Size keysize)
200191
{
201192
const JsonPathEntry *path1 = key1;
202193
const JsonPathEntry *path2 = key2;
@@ -211,23 +202,17 @@ JsonPathMatch(const void *key1, const void *key2, Size keysize)
211202
* JsonPathHash
212203
* Calculate hash of the path entry.
213204
*
214-
* XXX Again, maybe JsonPathEntryHash would be a better name?
215-
*
216-
* XXX Maybe should call JsonPathHash on the parent, instead of looking
217-
* at the field directly. Could easily happen we have not calculated it
218-
* yet, I guess.
205+
* Parent hash should be already calculated.
219206
*/
220207
static uint32
221-
JsonPathHash(const void *key, Size keysize)
208+
JsonPathEntryHash(const void *key, Size keysize)
222209
{
223210
const JsonPathEntry *path = key;
224-
225-
/* XXX Call JsonPathHash instead of direct access? */
226211
uint32 hash = path->parent ? path->parent->hash : 0;
227212

228213
hash = (hash << 1) | (hash >> 31);
229-
hash ^= path->len < 0 ? 0 : DatumGetUInt32(
230-
hash_any((const unsigned char *) path->entry, path->len));
214+
hash ^= path->len < 0 ? 0 :
215+
DatumGetUInt32(hash_any((const unsigned char *) path->entry, path->len));
231216

232217
return hash;
233218
}
@@ -241,7 +226,7 @@ JsonPathHash(const void *key, Size keysize)
241226
* updated.
242227
*/
243228
static inline JsonPathAnlStats *
244-
jsonAnalyzeAddPath(JsonAnalyzeContext *ctx, JsonPath parent,
229+
jsonAnalyzeAddPath(JsonAnalyzeContext *ctx, JsonPathEntry *parent,
245230
const char *entry, int len)
246231
{
247232
JsonPathEntry path;
@@ -252,7 +237,7 @@ jsonAnalyzeAddPath(JsonAnalyzeContext *ctx, JsonPath parent,
252237
path.parent = parent;
253238
path.entry = entry;
254239
path.len = len;
255-
path.hash = JsonPathHash(&path, 0);
240+
path.hash = JsonPathEntryHash(&path, 0);
256241

257242
/* XXX See if we already saw this path earlier. */
258243
stats = hash_search_with_hash_value(ctx->pathshash, &path, path.hash,
@@ -265,7 +250,7 @@ jsonAnalyzeAddPath(JsonAnalyzeContext *ctx, JsonPath parent,
265250
if (!found)
266251
{
267252
JsonPathAnlStats *parent = (JsonPathAnlStats *) stats->path.parent;
268-
JsonPath path = &stats->path;
253+
JsonPathEntry *path = &stats->path;
269254
const char *ppath = parent->pathstr;
270255
StringInfoData si;
271256
MemoryContext oldcxt = MemoryContextSwitchTo(ctx->mcxt);
@@ -586,7 +571,7 @@ jsonAnalyzeCollectPath(JsonAnalyzeContext *ctx, Jsonb *jb, void *param)
586571
JsonPathAnlStats *pstats = (JsonPathAnlStats *) param;
587572
JsonbValue jbvtmp;
588573
JsonbValue *jbv = JsonValueInitBinary(&jbvtmp, jb);
589-
JsonPath path;
574+
JsonPathEntry *path;
590575

591576
if (!pstats->entries)
592577
{
@@ -1100,8 +1085,8 @@ jsonAnalyzeInit(JsonAnalyzeContext *ctx, VacAttrStats *stats,
11001085
MemSet(&hash_ctl, 0, sizeof(hash_ctl));
11011086
hash_ctl.keysize = sizeof(JsonPathEntry);
11021087
hash_ctl.entrysize = sizeof(JsonPathAnlStats);
1103-
hash_ctl.hash = JsonPathHash;
1104-
hash_ctl.match = JsonPathMatch;
1088+
hash_ctl.hash = JsonPathEntryHash;
1089+
hash_ctl.match = JsonPathEntryMatch;
11051090
hash_ctl.hcxt = ctx->mcxt;
11061091

11071092
ctx->pathshash = hash_create("JSON analyze path table", 100, &hash_ctl,

0 commit comments

Comments
 (0)