Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4aee6a6

Browse files
committed
continue refactoring
1 parentff4809f commit4aee6a6

File tree

5 files changed

+90
-67
lines changed

5 files changed

+90
-67
lines changed

‎jsquery.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ struct JsQueryItem {
8080
JsQueryItem**elems;
8181
}array;
8282
};
83-
8483
};
8584

8685
typedefstructJsQueryItemR {
@@ -109,7 +108,8 @@ typedef struct JsQueryItemR {
109108

110109
}JsQueryItemR;
111110

112-
externvoidjsqInit(JsQueryItemR*v,char*base,int32pos);
111+
externvoidjsqInit(JsQueryItemR*v,JsQuery*js);
112+
externvoidjsqInitByBuffer(JsQueryItemR*v,char*base,int32pos);
113113
externbooljsqGetNext(JsQueryItemR*v,JsQueryItemR*a);
114114
externvoidjsqGetArg(JsQueryItemR*v,JsQueryItemR*a);
115115
externvoidjsqGetLeftArg(JsQueryItemR*v,JsQueryItemR*a);

‎jsquery_constr.c

Lines changed: 54 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,77 +20,84 @@
2020
#include"jsquery.h"
2121

2222
staticint32
23-
copyJsQuery(StringInfobuf,char*jqBase,int32jqPos)
23+
copyJsQuery(StringInfobuf,JsQueryItemR*jsq)
2424
{
25-
int32resPos=buf->len-VARHDRSZ;/* position from begining of jsquery data */
26-
JsQueryItemTypetype;
27-
int32nextPos,chld,next;
25+
JsQueryItemRelem;
26+
int32next,chld;
27+
int32resPos=buf->len-VARHDRSZ;/* position from begining of jsquery data */
2828

2929
check_stack_depth();
3030

31-
jqPos=readJsQueryHeader(jqBase,jqPos,&type,&nextPos);
32-
33-
appendStringInfoChar(buf, (char)type);
31+
appendStringInfoChar(buf, (char)jsq->type);
3432
alignStringInfoInt(buf);
3533

36-
next= (nextPos>0) ?buf->len :0;;
34+
next= (jsqGetNext(jsq,NULL)) ?buf->len :0;
3735
appendBinaryStringInfo(buf, (char*)&next/* fake value */,sizeof(next));
3836

39-
switch(type)
37+
switch(jsq->type)
4038
{
4139
casejqiKey:
4240
casejqiString:
4341
{
44-
int32len;
42+
int32len;
43+
char*s;
4544

46-
read_int32(len,jqBase,jqPos);
45+
s=jsqGetString(jsq,&len);
4746
appendBinaryStringInfo(buf, (char*)&len,sizeof(len));
48-
appendBinaryStringInfo(buf,jqBase+jqPos,len+1/* \0 */);
47+
appendBinaryStringInfo(buf,s,len+1/* \0 */);
4948
}
5049
break;
5150
casejqiNumeric:
52-
appendBinaryStringInfo(buf,jqBase+jqPos,VARSIZE(jqBase+jqPos));
51+
{
52+
Numericn=jsqGetNumeric(jsq);
53+
54+
appendBinaryStringInfo(buf, (char*)n,VARSIZE_ANY(n));
55+
}
5356
break;
5457
casejqiBool:
55-
appendBinaryStringInfo(buf,jqBase+jqPos,1);
58+
{
59+
boolv=jsqGetBool(jsq);
60+
61+
appendBinaryStringInfo(buf, (char*)&v,1);
62+
}
5663
break;
5764
casejqiArray:
5865
{
59-
int32i,nelems,arrayStart,*arrayPosIn;
66+
int32i,arrayStart;
6067

61-
read_int32(nelems,jqBase,jqPos);
62-
appendBinaryStringInfo(buf, (char*)&nelems/* fake value */,sizeof(nelems));
68+
appendBinaryStringInfo(buf, (char*)&jsq->array.nelems,
69+
sizeof(jsq->array.nelems));
6370

6471
arrayStart=buf->len;
65-
arrayPosIn= (int32*)(jqBase+jqPos);
6672

6773
/* reserve place for "pointers" to array's elements */
68-
for(i=0;i<nelems;i++)
74+
for(i=0;i<jsq->array.nelems;i++)
6975
appendBinaryStringInfo(buf, (char*)&i/* fake value */,sizeof(i));
7076

71-
for(i=0;i<nelems;i++)
77+
while(jsqIterateArray(jsq,&elem))
7278
{
73-
chld=copyJsQuery(buf,jqBase,arrayPosIn[i]);
79+
chld=copyJsQuery(buf,&elem);
7480
*(int32*)(buf->data+arrayStart+i*sizeof(i))=chld;
81+
i++;
7582
}
7683
}
7784
break;
7885
casejqiAnd:
7986
casejqiOr:
8087
{
81-
int32leftIn,rightIn,leftOut,rightOut;
88+
int32leftOut,rightOut;
8289

8390
leftOut=buf->len;
8491
appendBinaryStringInfo(buf, (char*)&leftOut/* fake value */,sizeof(leftOut));
8592
rightOut=buf->len;
8693
appendBinaryStringInfo(buf, (char*)&rightOut/* fake value */,sizeof(rightOut));
8794

88-
read_int32(leftIn,jqBase,jqPos);
89-
chld=copyJsQuery(buf,jqBase,leftIn);
95+
jsqGetLeftArg(jsq,&elem);
96+
chld=copyJsQuery(buf,&elem);
9097
*(int32*)(buf->data+leftOut)=chld;
9198

92-
read_int32(rightIn,jqBase,jqPos);
93-
chld=copyJsQuery(buf,jqBase,rightIn);
99+
jsqGetRightArg(jsq,&elem);
100+
chld=copyJsQuery(buf,&elem);
94101
*(int32*)(buf->data+rightOut)=chld;
95102
}
96103
break;
@@ -105,13 +112,12 @@ copyJsQuery(StringInfo buf, char *jqBase, int32 jqPos)
105112
casejqiOverlap:
106113
casejqiNot:
107114
{
108-
int32argIn,argOut;
115+
int32argOut=buf->len;
109116

110-
argOut=buf->len;
111117
appendBinaryStringInfo(buf, (char*)&argOut/* fake value */,sizeof(argOut));
112118

113-
read_int32(argIn,jqBase,jqPos);
114-
chld=copyJsQuery(buf,jqBase,argIn);
119+
jsqGetArg(jsq,&elem);
120+
chld=copyJsQuery(buf,&elem);
115121
*(int32*)(buf->data+argOut)=chld;
116122
}
117123
break;
@@ -122,11 +128,11 @@ copyJsQuery(StringInfo buf, char *jqBase, int32 jqPos)
122128
casejqiAnyKey:
123129
break;
124130
default:
125-
elog(ERROR,"Unknown JsQueryItem type: %d",type);
131+
elog(ERROR,"Unknown JsQueryItem type: %d",jsq->type);
126132
}
127133

128-
if (nextPos)
129-
*(int32*)(buf->data+next)=copyJsQuery(buf,jqBase,nextPos);
134+
if (jsqGetNext(jsq,&elem))
135+
*(int32*)(buf->data+next)=copyJsQuery(buf,&elem);
130136

131137
returnresPos;
132138
}
@@ -137,27 +143,32 @@ joinJsQuery(JsQueryItemType type, JsQuery *jq1, JsQuery *jq2)
137143
JsQuery*out;
138144
StringInfoDatabuf;
139145
int32left,right,chld;
146+
JsQueryItemRv;
140147

141148
initStringInfo(&buf);
142149
enlargeStringInfo(&buf,VARSIZE_ANY(jq1)+VARSIZE_ANY(jq2)+4*sizeof(int32)+VARHDRSZ);
143150

144151
appendStringInfoSpaces(&buf,VARHDRSZ);
145152

153+
/* form jqiAnd/jqiOr header */
146154
appendStringInfoChar(&buf, (char)type);
147155
alignStringInfoInt(&buf);
148156

149-
/*next*/
150-
chld=0;
157+
/*nextPos field of header*/
158+
chld=0;/* actual value, not a fake */
151159
appendBinaryStringInfo(&buf, (char*)&chld,sizeof(chld));
152160

153161
left=buf.len;
154162
appendBinaryStringInfo(&buf, (char*)&left/* fake value */,sizeof(left));
155163
right=buf.len;
156164
appendBinaryStringInfo(&buf, (char*)&right/* fake value */,sizeof(right));
157165

158-
chld=copyJsQuery(&buf,VARDATA(jq1),0);
166+
/* dump left and right subtree */
167+
jsqInit(&v,jq1);
168+
chld=copyJsQuery(&buf,&v);
159169
*(int32*)(buf.data+left)=chld;
160-
chld=copyJsQuery(&buf,VARDATA(jq2),0);
170+
jsqInit(&v,jq2);
171+
chld=copyJsQuery(&buf,&v);
161172
*(int32*)(buf.data+right)=chld;
162173

163174
out= (JsQuery*)buf.data;
@@ -206,23 +217,26 @@ jsquery_not(PG_FUNCTION_ARGS)
206217
JsQuery*out;
207218
StringInfoDatabuf;
208219
int32arg,chld;
220+
JsQueryItemRv;
209221

210222
initStringInfo(&buf);
211223
enlargeStringInfo(&buf,VARSIZE_ANY(jq)+4*sizeof(int32)+VARHDRSZ);
212224

213225
appendStringInfoSpaces(&buf,VARHDRSZ);
214226

227+
/* form jsquery header */
215228
appendStringInfoChar(&buf, (char)jqiNot);
216229
alignStringInfoInt(&buf);
217230

218-
/*next*/
219-
chld=0;
231+
/*nextPos field of header*/
232+
chld=0;/* actual value, not a fake */
220233
appendBinaryStringInfo(&buf, (char*)&chld,sizeof(chld));
221234

222235
arg=buf.len;
223236
appendBinaryStringInfo(&buf, (char*)&arg/* fake value */,sizeof(arg));
224237

225-
chld=copyJsQuery(&buf,VARDATA(jq),0);
238+
jsqInit(&v,jq);
239+
chld=copyJsQuery(&buf,&v);
226240
*(int32*)(buf.data+arg)=chld;
227241

228242
out= (JsQuery*)buf.data;

‎jsquery_io.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ printJsQueryItem(StringInfo buf, JsQueryItemR *v, bool inKey, bool printBrackete
228228
casejqiKey:
229229
if (inKey)
230230
appendStringInfoChar(buf,'.');
231+
/* follow next */
231232
casejqiString:
232233
escape_json(buf,jsqGetString(v,NULL));
233234
break;
@@ -331,7 +332,7 @@ jsquery_out(PG_FUNCTION_ARGS)
331332
initStringInfo(&buf);
332333
enlargeStringInfo(&buf,VARSIZE(in)/* estimation */);
333334

334-
jsqInit(&v,VARDATA(in),0);
335+
jsqInit(&v,in);
335336
printJsQueryItem(&buf,&v, false, true);
336337

337338
PG_RETURN_CSTRING(buf.data);

‎jsquery_op.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ executeExpr(JsQueryItemR *jsq, int32 op, JsonbValue *jb)
273273
/*
274274
* read arg type
275275
*/
276-
Assert(jsq->nextPos==0);
276+
Assert(jsqGetNext(jsq,NULL)==false);
277277
Assert(jsq->type==jqiAny||jsq->type==jqiString||jsq->type==jqiNumeric||
278278
jsq->type==jqiNull||jsq->type==jqiBool||jsq->type==jqiArray);
279279

@@ -448,7 +448,7 @@ jsquery_json_exec(PG_FUNCTION_ARGS)
448448
jbv.val.binary.data=&jb->root;
449449
jbv.val.binary.len=VARSIZE_ANY_EXHDR(jb);
450450

451-
jsqInit(&jsq,VARDATA(jq),0);
451+
jsqInit(&jsq,jq);
452452

453453
res=recursiveExecute(&jsq,&jbv);
454454

@@ -472,7 +472,7 @@ json_jsquery_exec(PG_FUNCTION_ARGS)
472472
jbv.val.binary.data=&jb->root;
473473
jbv.val.binary.len=VARSIZE_ANY_EXHDR(jb);
474474

475-
jsqInit(&jsq,VARDATA(jq),0);
475+
jsqInit(&jsq,jq);
476476

477477
res=recursiveExecute(&jsq,&jbv);
478478

@@ -591,8 +591,8 @@ jsquery_cmp(PG_FUNCTION_ARGS)
591591
int32res;
592592
JsQueryItemRv1,v2;
593593

594-
jsqInit(&v1,VARDATA(jq1),0);
595-
jsqInit(&v2,VARDATA(jq2),0);
594+
jsqInit(&v1,jq1);
595+
jsqInit(&v2,jq2);
596596

597597
res=compareJsQuery(&v1,&v2);
598598

@@ -611,8 +611,8 @@ jsquery_lt(PG_FUNCTION_ARGS)
611611
int32res;
612612
JsQueryItemRv1,v2;
613613

614-
jsqInit(&v1,VARDATA(jq1),0);
615-
jsqInit(&v2,VARDATA(jq2),0);
614+
jsqInit(&v1,jq1);
615+
jsqInit(&v2,jq2);
616616

617617
res=compareJsQuery(&v1,&v2);
618618

@@ -631,8 +631,8 @@ jsquery_le(PG_FUNCTION_ARGS)
631631
int32res;
632632
JsQueryItemRv1,v2;
633633

634-
jsqInit(&v1,VARDATA(jq1),0);
635-
jsqInit(&v2,VARDATA(jq2),0);
634+
jsqInit(&v1,jq1);
635+
jsqInit(&v2,jq2);
636636

637637
res=compareJsQuery(&v1,&v2);
638638

@@ -651,8 +651,8 @@ jsquery_eq(PG_FUNCTION_ARGS)
651651
int32res;
652652
JsQueryItemRv1,v2;
653653

654-
jsqInit(&v1,VARDATA(jq1),0);
655-
jsqInit(&v2,VARDATA(jq2),0);
654+
jsqInit(&v1,jq1);
655+
jsqInit(&v2,jq2);
656656

657657
res=compareJsQuery(&v1,&v2);
658658

@@ -671,8 +671,8 @@ jsquery_ne(PG_FUNCTION_ARGS)
671671
int32res;
672672
JsQueryItemRv1,v2;
673673

674-
jsqInit(&v1,VARDATA(jq1),0);
675-
jsqInit(&v2,VARDATA(jq2),0);
674+
jsqInit(&v1,jq1);
675+
jsqInit(&v2,jq2);
676676

677677
res=compareJsQuery(&v1,&v2);
678678

@@ -691,8 +691,8 @@ jsquery_ge(PG_FUNCTION_ARGS)
691691
int32res;
692692
JsQueryItemRv1,v2;
693693

694-
jsqInit(&v1,VARDATA(jq1),0);
695-
jsqInit(&v2,VARDATA(jq2),0);
694+
jsqInit(&v1,jq1);
695+
jsqInit(&v2,jq2);
696696

697697
res=compareJsQuery(&v1,&v2);
698698

@@ -711,8 +711,8 @@ jsquery_gt(PG_FUNCTION_ARGS)
711711
int32res;
712712
JsQueryItemRv1,v2;
713713

714-
jsqInit(&v1,VARDATA(jq1),0);
715-
jsqInit(&v2,VARDATA(jq2),0);
714+
jsqInit(&v1,jq1);
715+
jsqInit(&v2,jq2);
716716

717717
res=compareJsQuery(&v1,&v2);
718718

@@ -805,7 +805,7 @@ jsquery_hash(PG_FUNCTION_ARGS)
805805
pg_crc32res;
806806

807807
INIT_CRC32(res);
808-
jsqInit(&v,VARDATA(jq),0);
808+
jsqInit(&v,jq);
809809
hashJsQuery(&v,&res);
810810
FIN_CRC32(res);
811811

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp