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

Commit 5509fb1

Browse files
author
Nikita Glukhov
committed
Switch to relative jsonpath item offsets
1 parent ab1f0da commit 5509fb1

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

src/backend/utils/adt/jsonpath.c

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ flattenJsonPathParseItem(StringInfo buf, JsonPathParseItem *item,
9999
allowCurrent ||
100100
allowCurrentInArg,
101101
insideArraySubscript);
102-
*(int32*)(buf->data + left) = chld;
102+
*(int32*)(buf->data + left) = chld - pos;
103103
chld = flattenJsonPathParseItem(buf, item->value.args.right,
104104
allowCurrent ||
105105
allowCurrentInArg,
106106
insideArraySubscript);
107-
*(int32*)(buf->data + right) = chld;
107+
*(int32*)(buf->data + right) = chld - pos;
108108
}
109109
break;
110110
case jpiLikeRegex:
@@ -127,7 +127,7 @@ flattenJsonPathParseItem(StringInfo buf, JsonPathParseItem *item,
127127
chld = flattenJsonPathParseItem(buf, item->value.like_regex.expr,
128128
allowCurrent,
129129
insideArraySubscript);
130-
*(int32 *)(buf->data + offs) = chld;
130+
*(int32 *)(buf->data + offs) = chld - pos;
131131
}
132132
break;
133133
case jpiFilter:
@@ -154,7 +154,7 @@ flattenJsonPathParseItem(StringInfo buf, JsonPathParseItem *item,
154154
allowCurrent ||
155155
allowCurrentInArg,
156156
insideArraySubscript);
157-
*(int32*)(buf->data + arg) = chld;
157+
*(int32*)(buf->data + arg) = chld - pos;
158158
}
159159
break;
160160
case jpiNull:
@@ -195,12 +195,12 @@ flattenJsonPathParseItem(StringInfo buf, JsonPathParseItem *item,
195195
int32 frompos =
196196
flattenJsonPathParseItem(buf,
197197
item->value.array.elems[i].from,
198-
true, true);
198+
true, true) - pos;
199199

200200
if (item->value.array.elems[i].to)
201201
topos = flattenJsonPathParseItem(buf,
202202
item->value.array.elems[i].to,
203-
true, true);
203+
true, true) - pos;
204204
else
205205
topos = 0;
206206

@@ -243,11 +243,11 @@ flattenJsonPathParseItem(StringInfo buf, JsonPathParseItem *item,
243243

244244
foreach(lc, item->value.sequence.elems)
245245
{
246-
int32 pos =
246+
int32 elempos =
247247
flattenJsonPathParseItem(buf, lfirst(lc),
248248
allowCurrent, insideArraySubscript);
249249

250-
*(int32 *) &buf->data[offset] = pos;
250+
*(int32 *) &buf->data[offset] = elempos - pos;
251251
offset += sizeof(int32);
252252
}
253253
}
@@ -277,8 +277,8 @@ flattenJsonPathParseItem(StringInfo buf, JsonPathParseItem *item,
277277
insideArraySubscript);
278278
int32 *ppos = (int32 *) &buf->data[offset];
279279

280-
ppos[0] = keypos;
281-
ppos[1] = valpos;
280+
ppos[0] = keypos - pos;
281+
ppos[1] = valpos - pos;
282282

283283
offset += 2 * sizeof(int32);
284284
}
@@ -291,7 +291,7 @@ flattenJsonPathParseItem(StringInfo buf, JsonPathParseItem *item,
291291
if (item->next)
292292
*(int32*)(buf->data + next) =
293293
flattenJsonPathParseItem(buf, item->next, allowCurrent,
294-
insideArraySubscript);
294+
insideArraySubscript) - pos;
295295

296296
return pos;
297297
}
@@ -763,18 +763,10 @@ jspInit(JsonPathItem *v, JsonPath *js)
763763
void
764764
jspInitByBuffer(JsonPathItem *v, char *base, int32 pos)
765765
{
766-
v->base = base;
766+
v->base = base + pos;
767767

768768
read_byte(v->type, base, pos);
769-
770-
switch(INTALIGN(pos) - pos)
771-
{
772-
case 3: pos++;
773-
case 2: pos++;
774-
case 1: pos++;
775-
default: break;
776-
}
777-
769+
pos = INTALIGN((uintptr_t)(base + pos)) - (uintptr_t) base;
778770
read_int32(v->nextPos, base, pos);
779771

780772
switch(v->type)

0 commit comments

Comments
 (0)