Skip to content
This repository was archived by the owner on Apr 20, 2022. It is now read-only.

Commit f7b3b70

Browse files
committed
Don't use if (!expr) {} else {}
The correct way is: if (expr) {} else {} Change-Id: I191b4f7ac33a1fef68a7ffb91ccb2bba76001fa8 Reviewed-on: http://review.couchbase.org/27388 Reviewed-by: Trond Norbye <trond.norbye@gmail.com> Tested-by: Trond Norbye <trond.norbye@gmail.com>
1 parent abdb1f8 commit f7b3b70

File tree

1 file changed

+87
-85
lines changed

1 file changed

+87
-85
lines changed

store.c

Lines changed: 87 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -89,91 +89,7 @@ void php_couchbase_store_impl(INTERNAL_FUNCTION_PARAMETERS, lcb_storage_t op, in
8989
long expire = 0, cas_len = 0;
9090
char *key = NULL;
9191

92-
if (!multi) {
93-
char *key = NULL;
94-
zval *value;
95-
long klen = 0;
96-
PHP_COUCHBASE_GET_PARAMS(couchbase_res,
97-
PHP_COUCHBASE_ARG_F_FUNCTIONAL,
98-
"sz|ls",
99-
&key, &klen,
100-
&value,
101-
&expire,
102-
&cas, &cas_len);
103-
104-
if (pcbc_check_expiry(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0,
105-
expire, &exp) == -1) {
106-
/* Incorrect expiry time */
107-
return;
108-
}
109-
110-
if (!klen) {
111-
couchbase_report_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0,
112-
cb_illegal_key_exception,
113-
"No key specified: Empty key");
114-
return;
115-
}
116-
117-
if (cas) {
118-
char *e;
119-
cas_v = (lcb_cas_t)strtoull(cas, &e, 10);
120-
if (*e != '\0') {
121-
couchbase_report_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0,
122-
cb_illegal_key_exception,
123-
"Invalid CAS specified");
124-
return;
125-
}
126-
}
127-
128-
payload = php_couchbase_zval_to_payload(value, &payload_len,
129-
&flags,
130-
couchbase_res->serializer,
131-
couchbase_res->compressor
132-
TSRMLS_CC);
133-
if (payload == NULL) {
134-
RETURN_FALSE;
135-
}
136-
137-
if (couchbase_res->prefix_key_len) {
138-
klen = spprintf(&key, 0, "%s_%s", couchbase_res->prefix_key, key);
139-
}
140-
141-
ctx = ecalloc(1, sizeof(php_couchbase_ctx));
142-
ctx->res = couchbase_res;
143-
ctx->rv = return_value;
144-
couchbase_res->seqno += 1;
145-
146-
{
147-
lcb_store_cmd_t cmd;
148-
lcb_store_cmd_t *commands[] = { &cmd };
149-
memset(&cmd, 0, sizeof(cmd));
150-
cmd.v.v0.operation = op;
151-
cmd.v.v0.key = key;
152-
cmd.v.v0.nkey = klen;
153-
cmd.v.v0.bytes = payload;
154-
cmd.v.v0.nbytes = payload_len;
155-
cmd.v.v0.flags = flags;
156-
cmd.v.v0.exptime = exp;
157-
cmd.v.v0.cas = (uint64_t)cas_v;
158-
159-
retval = lcb_store(couchbase_res->handle, ctx,
160-
1, (const lcb_store_cmd_t * const *)commands);
161-
}
162-
163-
efree(payload);
164-
if (couchbase_res->prefix_key_len) {
165-
efree(key);
166-
}
167-
if (LCB_SUCCESS != retval) {
168-
efree(ctx);
169-
couchbase_report_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0,
170-
cb_lcb_exception,
171-
"Failed to schedule set request: %s",
172-
lcb_strerror(couchbase_res->handle, retval));
173-
return;
174-
}
175-
176-
} else { /* multi */
92+
if (multi) { /* multi-get */
17793
zval *akeys, **ppzval;
17894
char *key = NULL;
17995
uint klen = 0;
@@ -270,7 +186,93 @@ void php_couchbase_store_impl(INTERNAL_FUNCTION_PARAMETERS, lcb_storage_t op, in
270186
return;
271187
}
272188
couchbase_res->seqno += nkey;
189+
} else {
190+
/* single-get */
191+
char *key = NULL;
192+
zval *value;
193+
long klen = 0;
194+
PHP_COUCHBASE_GET_PARAMS(couchbase_res,
195+
PHP_COUCHBASE_ARG_F_FUNCTIONAL,
196+
"sz|ls",
197+
&key, &klen,
198+
&value,
199+
&expire,
200+
&cas, &cas_len);
201+
202+
if (pcbc_check_expiry(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0,
203+
expire, &exp) == -1) {
204+
/* Incorrect expiry time */
205+
return;
206+
}
207+
208+
if (!klen) {
209+
couchbase_report_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0,
210+
cb_illegal_key_exception,
211+
"No key specified: Empty key");
212+
return;
213+
}
214+
215+
if (cas) {
216+
char *e;
217+
cas_v = (lcb_cas_t)strtoull(cas, &e, 10);
218+
if (*e != '\0') {
219+
couchbase_report_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0,
220+
cb_illegal_key_exception,
221+
"Invalid CAS specified");
222+
return;
223+
}
224+
}
225+
226+
payload = php_couchbase_zval_to_payload(value, &payload_len,
227+
&flags,
228+
couchbase_res->serializer,
229+
couchbase_res->compressor
230+
TSRMLS_CC);
231+
if (payload == NULL) {
232+
RETURN_FALSE;
233+
}
234+
235+
if (couchbase_res->prefix_key_len) {
236+
klen = spprintf(&key, 0, "%s_%s", couchbase_res->prefix_key, key);
237+
}
238+
239+
ctx = ecalloc(1, sizeof(php_couchbase_ctx));
240+
ctx->res = couchbase_res;
241+
ctx->rv = return_value;
242+
couchbase_res->seqno += 1;
243+
244+
{
245+
lcb_store_cmd_t cmd;
246+
lcb_store_cmd_t *commands[] = { &cmd };
247+
memset(&cmd, 0, sizeof(cmd));
248+
cmd.v.v0.operation = op;
249+
cmd.v.v0.key = key;
250+
cmd.v.v0.nkey = klen;
251+
cmd.v.v0.bytes = payload;
252+
cmd.v.v0.nbytes = payload_len;
253+
cmd.v.v0.flags = flags;
254+
cmd.v.v0.exptime = exp;
255+
cmd.v.v0.cas = (uint64_t)cas_v;
256+
257+
retval = lcb_store(couchbase_res->handle, ctx,
258+
1, (const lcb_store_cmd_t * const *)commands);
259+
}
260+
261+
efree(payload);
262+
if (couchbase_res->prefix_key_len) {
263+
efree(key);
264+
}
265+
if (LCB_SUCCESS != retval) {
266+
efree(ctx);
267+
couchbase_report_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0,
268+
cb_lcb_exception,
269+
"Failed to schedule set request: %s",
270+
lcb_strerror(couchbase_res->handle, retval));
271+
return;
272+
}
273+
273274
}
275+
274276
{
275277
pcbc_start_loop(couchbase_res);
276278
if (IS_ARRAY != Z_TYPE_P(return_value)) {

0 commit comments

Comments
 (0)