@@ -92,17 +92,16 @@ flattenJsonPathParseItem(StringInfo buf, JsonPathParseItem *item,
9292 right = buf -> len ;
9393 appendBinaryStringInfo (buf , (char * )& right /* fake value */ , sizeof (right ));
9494
95- chld = !item -> value .args .left ? 0 :
95+ chld = !item -> value .args .left ? pos :
9696 flattenJsonPathParseItem (buf , item -> value .args .left ,
9797 allowCurrent ,
9898 insideArraySubscript );
99- * (int32 * )(buf -> data + left ) = chld ;
100-
101- chld = !item -> value .args .right ? 0 :
99+ * (int32 * )(buf -> data + left ) = chld - pos ;
100+ chld = !item -> value .args .right ? pos :
102101 flattenJsonPathParseItem (buf , item -> value .args .right ,
103102 allowCurrent ,
104103 insideArraySubscript );
105- * (int32 * )(buf -> data + right ) = chld ;
104+ * (int32 * )(buf -> data + right ) = chld - pos ;
106105 }
107106 break ;
108107 case jpiLikeRegex :
@@ -125,7 +124,7 @@ flattenJsonPathParseItem(StringInfo buf, JsonPathParseItem *item,
125124 chld = flattenJsonPathParseItem (buf , item -> value .like_regex .expr ,
126125 allowCurrent ,
127126 insideArraySubscript );
128- * (int32 * )(buf -> data + offs ) = chld ;
127+ * (int32 * )(buf -> data + offs ) = chld - pos ;
129128 }
130129 break ;
131130 case jpiFilter :
@@ -144,7 +143,7 @@ flattenJsonPathParseItem(StringInfo buf, JsonPathParseItem *item,
144143 item -> type == jpiFilter ||
145144 allowCurrent ,
146145 insideArraySubscript );
147- * (int32 * )(buf -> data + arg ) = chld ;
146+ * (int32 * )(buf -> data + arg ) = chld - pos ;
148147 }
149148 break ;
150149 case jpiNull :
@@ -185,12 +184,12 @@ flattenJsonPathParseItem(StringInfo buf, JsonPathParseItem *item,
185184 int32 frompos =
186185 flattenJsonPathParseItem (buf ,
187186 item -> value .array .elems [i ].from ,
188- true, true);
187+ true, true) - pos ;
189188
190189 if (item -> value .array .elems [i ].to )
191190 topos = flattenJsonPathParseItem (buf ,
192191 item -> value .array .elems [i ].to ,
193- true, true);
192+ true, true) - pos ;
194193 else
195194 topos = 0 ;
196195
@@ -224,7 +223,7 @@ flattenJsonPathParseItem(StringInfo buf, JsonPathParseItem *item,
224223 if (item -> next )
225224 {
226225 chld = flattenJsonPathParseItem (buf , item -> next , allowCurrent ,
227- insideArraySubscript );
226+ insideArraySubscript ) - pos ;
228227 * (int32 * )(buf -> data + next ) = chld ;
229228 }
230229
@@ -626,18 +625,10 @@ jspInit(JsonPathItem *v, JsonPath *js)
626625void
627626jspInitByBuffer (JsonPathItem * v , char * base , int32 pos )
628627{
629- v -> base = base ;
628+ v -> base = base + pos ;
630629
631630 read_byte (v -> type , base , pos );
632-
633- switch (INTALIGN (pos ) - pos )
634- {
635- case 3 : pos ++ ;
636- case 2 : pos ++ ;
637- case 1 : pos ++ ;
638- default : break ;
639- }
640-
631+ pos = INTALIGN ((uintptr_t )(base + pos )) - (uintptr_t ) base ;
641632 read_int32 (v -> nextPos , base , pos );
642633
643634 switch (v -> type )
0 commit comments