Skip to content

Commit b0094a7

Browse files
committed
use separate JsQueryItemType enum instead of included in struct
1 parent a0899ff commit b0094a7

File tree

5 files changed

+40
-38
lines changed

5 files changed

+40
-38
lines changed

jsquery.h

+8-7
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ typedef struct
2929
#define PG_GETARG_JSQUERY(x) DatumGetJsQueryP(PG_GETARG_DATUM(x))
3030
#define PG_RETURN_JSQUERY(p) PG_RETURN_POINTER(p)
3131

32-
33-
typedef struct JsQueryItem JsQueryItem;
34-
35-
struct JsQueryItem {
36-
enum {
32+
typedef enum JsQueryItemType {
3733
jqiNull = jbvNull,
3834
jqiString = jbvString,
3935
jqiNumeric = jbvNumeric,
@@ -56,7 +52,12 @@ struct JsQueryItem {
5652
jqiKey = 'K',
5753
jqiCurrent = '$',
5854
jqiIn = 'I'
59-
} type;
55+
} JsQueryItemType;
56+
57+
typedef struct JsQueryItem JsQueryItem;
58+
59+
struct JsQueryItem {
60+
JsQueryItemType type;
6061

6162
union {
6263
struct {
@@ -88,7 +89,7 @@ struct JsQueryItem {
8889

8990
extern JsQueryItem* parsejsquery(const char *str, int len);
9091

91-
int32 readJsQueryHeader(char *base, int32 pos, int32 *type, int32 *nextPos);
92+
int32 readJsQueryHeader(char *base, int32 pos, JsQueryItemType *type, int32 *nextPos);
9293

9394
#define read_byte(v, b, p) do { \
9495
(v) = *(int8*)((b) + (p)); \

jsquery_constr.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
static int32
2323
copyJsQuery(StringInfo buf, char *jqBase, int32 jqPos)
2424
{
25-
int32 resPos = buf->len - VARHDRSZ; /* position from begining of jsquery data */
26-
int32 type, nextPos, chld, next;
25+
int32 resPos = buf->len - VARHDRSZ; /* position from begining of jsquery data */
26+
JsQueryItemType type;
27+
int32 nextPos, chld, next;
2728

2829
check_stack_depth();
2930

@@ -131,7 +132,7 @@ copyJsQuery(StringInfo buf, char *jqBase, int32 jqPos)
131132
}
132133

133134
static JsQuery*
134-
joinJsQuery(int32 type, JsQuery *jq1, JsQuery *jq2)
135+
joinJsQuery(JsQueryItemType type, JsQuery *jq1, JsQuery *jq2)
135136
{
136137
JsQuery *out;
137138
StringInfoData buf;

jsquery_extract.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ static int compareJsQueryValue(JsQueryValue *v1, JsQueryValue *v2);
2222
static ExtractedNode *
2323
recursiveExtract(char *jqBase, int32 jqPos, bool indirect, PathItem *path)
2424
{
25-
int32 type, childType;
26-
int32 nextPos;
27-
int32 left, right, arg;
28-
ExtractedNode *leftNode, *rightNode, *result;
29-
int32 len, *arrayPos, nelems, i;
30-
PathItem *pathItem;
25+
JsQueryItemType type, childType;
26+
int32 nextPos;
27+
int32 left, right, arg;
28+
ExtractedNode *leftNode, *rightNode, *result;
29+
int32 len, *arrayPos, nelems, i;
30+
PathItem *pathItem;
3131

3232
check_stack_depth();
3333

jsquery_io.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ jsquery_in(PG_FUNCTION_ARGS)
166166
}
167167

168168
int32
169-
readJsQueryHeader(char *base, int32 pos, int32 *type, int32 *nextPos)
169+
readJsQueryHeader(char *base, int32 pos, JsQueryItemType *type, int32 *nextPos)
170170
{
171171
read_byte(*type, base, pos);
172172
switch(INTALIGN(pos) - pos)
@@ -183,7 +183,7 @@ readJsQueryHeader(char *base, int32 pos, int32 *type, int32 *nextPos)
183183

184184

185185
static void
186-
printOperation(StringInfo buf, int type)
186+
printOperation(StringInfo buf, JsQueryItemType type)
187187
{
188188
switch(type)
189189
{
@@ -215,8 +215,8 @@ printOperation(StringInfo buf, int type)
215215
static void
216216
printJsQueryItem(StringInfo buf, char *base, int32 pos, bool inKey, bool printBracketes)
217217
{
218-
int32 type;
219-
int32 nextPos;
218+
JsQueryItemType type;
219+
int32 nextPos;
220220

221221
check_stack_depth();
222222

jsquery_op.c

+18-18
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ recursiveAny(char *jqBase, int32 jqPos, JsonbValue *jb)
9292
}
9393

9494
static bool
95-
checkEquality(char *jqBase, int32 jqPos, int32 type, JsonbValue *jb)
95+
checkEquality(char *jqBase, int32 jqPos, JsQueryItemType type, JsonbValue *jb)
9696
{
9797
int len;
9898

@@ -123,7 +123,7 @@ checkEquality(char *jqBase, int32 jqPos, int32 type, JsonbValue *jb)
123123
}
124124

125125
static bool
126-
checkArrayEquality(char *jqBase, int32 jqPos, int32 type, JsonbValue *jb)
126+
checkArrayEquality(char *jqBase, int32 jqPos, JsQueryItemType type, JsonbValue *jb)
127127
{
128128
int32 i, nelems, *arrayPos;
129129
int32 r;
@@ -159,7 +159,7 @@ checkArrayEquality(char *jqBase, int32 jqPos, int32 type, JsonbValue *jb)
159159
}
160160

161161
static bool
162-
checkIn(char *jqBase, int32 jqPos, int32 type, JsonbValue *jb)
162+
checkIn(char *jqBase, int32 jqPos, JsQueryItemType type, JsonbValue *jb)
163163
{
164164
int32 i, nelems, *arrayPos;
165165

@@ -180,7 +180,7 @@ checkIn(char *jqBase, int32 jqPos, int32 type, JsonbValue *jb)
180180
}
181181

182182
static bool
183-
executeArrayOp(char *jqBase, int32 jqPos, int32 type, int32 op, JsonbValue *jb)
183+
executeArrayOp(char *jqBase, int32 jqPos, JsQueryItemType type, int32 op, JsonbValue *jb)
184184
{
185185
int32 i, nelems, *arrayPos;
186186
int32 r;
@@ -252,7 +252,7 @@ executeArrayOp(char *jqBase, int32 jqPos, int32 type, int32 op, JsonbValue *jb)
252252
}
253253

254254
static bool
255-
makeCompare(char *jqBase, int32 jqPos, int32 type, int32 op, JsonbValue *jb)
255+
makeCompare(char *jqBase, int32 jqPos, JsQueryItemType type, int32 op, JsonbValue *jb)
256256
{
257257
int res;
258258

@@ -283,8 +283,8 @@ makeCompare(char *jqBase, int32 jqPos, int32 type, int32 op, JsonbValue *jb)
283283
static bool
284284
executeExpr(char *jqBase, int32 jqPos, int32 op, JsonbValue *jb)
285285
{
286-
int32 type;
287-
int32 nextPos;
286+
JsQueryItemType type;
287+
int32 nextPos;
288288

289289
check_stack_depth();
290290

@@ -324,10 +324,10 @@ executeExpr(char *jqBase, int32 jqPos, int32 op, JsonbValue *jb)
324324
static bool
325325
recursiveExecute(char *jqBase, int32 jqPos, JsonbValue *jb)
326326
{
327-
int32 type;
328-
int32 nextPos;
329-
int32 left, right, arg;
330-
bool res = false;
327+
JsQueryItemType type;
328+
int32 nextPos;
329+
int32 left, right, arg;
330+
bool res = false;
331331

332332
check_stack_depth();
333333

@@ -497,11 +497,11 @@ json_jsquery_exec(PG_FUNCTION_ARGS)
497497
static int
498498
compareJsQuery(char *base1, int32 pos1, char *base2, int32 pos2)
499499
{
500-
int32 type1,
501-
nextPos1,
502-
type2,
503-
nextPos2;
504-
int32 res = 0;
500+
JsQueryItemType type1,
501+
type2;
502+
int32 nextPos1,
503+
nextPos2;
504+
int32 res = 0;
505505

506506
check_stack_depth();
507507

@@ -730,8 +730,8 @@ jsquery_gt(PG_FUNCTION_ARGS)
730730
static void
731731
hashJsQuery(char *base, int32 pos, pg_crc32 *crc)
732732
{
733-
int32 type;
734-
int32 nextPos;
733+
JsQueryItemType type;
734+
int32 nextPos;
735735

736736
check_stack_depth();
737737

0 commit comments

Comments
 (0)