#include "php_http_api.h"
-#include <ext/standard/php_lcg.h>
-#include <zend_exceptions.h>
+#include "ext/standard/php_lcg.h"
+#include "zend_exceptions.h"
/* SLEEP */
void php_http_sleep(double s)
{
-#if defined(PHP_WIN32)
+#if PHP_WIN32
Sleep((DWORD) PHP_HTTP_MSEC(s));
-#elif defined(HAVE_USLEEP)
+#elif HAVE_USLEEP
usleep(PHP_HTTP_USEC(s));
-#elif defined(HAVE_NANOSLEEP)
+#elif HAVE_NANOSLEEP
struct timespec req, rem;
req.tv_sec = (time_t) s;
{
int result = 0;
- if (!haystack_str || !needle_str) {
+ if (UNEXPECTED(!haystack_str || !needle_str)) {
return result;
}
- if (flags & PHP_HTTP_MATCH_FULL) {
+ if (UNEXPECTED(flags & PHP_HTTP_MATCH_FULL)) {
if (flags & PHP_HTTP_MATCH_CASE) {
result = !strcmp(haystack_str, needle_str);
} else {
const char *found;
char *haystack = estrdup(haystack_str), *needle = estrdup(needle_str);
- if (flags & PHP_HTTP_MATCH_CASE) {
+ if (UNEXPECTED(flags & PHP_HTTP_MATCH_CASE)) {
found = zend_memnstr(haystack, needle, strlen(needle), haystack+strlen(haystack));
} else {
found = php_stristr(haystack, needle, strlen(haystack), strlen(needle));
if (found) {
if (!(flags & PHP_HTTP_MATCH_WORD)
|| ( (found == haystack || !PHP_HTTP_IS_CTYPE(alnum, *(found - 1)))
- && (!*(found + strlen(needle)) || !PHP_HTTP_IS_CTYPE(alnum, *(found + strlen(needle))))
+ && EXPECTED(!*(found + strlen(needle)) || !PHP_HTTP_IS_CTYPE(alnum, *(found + strlen(needle))))
)
) {
result = 1;
return result;
}
-char *php_http_pretty_key(register char *key, size_t key_len, zend_bool uctitle, zend_bool xhyphen)
+char *php_http_pretty_key(char *key, size_t key_len, zend_bool uctitle, zend_bool xhyphen)
{
- size_t i = 1;
+ size_t i;
int wasalpha;
if (key && key_len) {
- if ((wasalpha = PHP_HTTP_IS_CTYPE(alpha, key[0]))) {
- key[0] = (char) (uctitle ? PHP_HTTP_TO_CTYPE(upper, key[0]) : PHP_HTTP_TO_CTYPE(lower, key[0]));
+ if (EXPECTED(wasalpha = PHP_HTTP_IS_CTYPE(alpha, key[0]))) {
+ if (EXPECTED(uctitle)) {
+ key[0] = PHP_HTTP_TO_CTYPE(upper, key[0]);
+ } else {
+ key[0] = PHP_HTTP_TO_CTYPE(lower, key[0]);
+ }
}
- PHP_HTTP_DUFF(key_len,
- if (PHP_HTTP_IS_CTYPE(alpha, key[i])) {
- key[i] = (char) (((!wasalpha) && uctitle) ? PHP_HTTP_TO_CTYPE(upper, key[i]) : PHP_HTTP_TO_CTYPE(lower, key[i]));
- wasalpha = 1;
+ for (i = 1; i < key_len; ++i) {
+ if (EXPECTED(PHP_HTTP_IS_CTYPE(alpha, key[i]))) {
+ if (EXPECTED(wasalpha)) {
+ key[i] = PHP_HTTP_TO_CTYPE(lower, key[i]);
+ } else if (EXPECTED(uctitle)) {
+ key[i] = PHP_HTTP_TO_CTYPE(upper, key[i]);
+ wasalpha = 1;
+ } else {
+ key[i] = PHP_HTTP_TO_CTYPE(lower, key[i]);
+ wasalpha = 1;
+ }
} else {
- if (xhyphen && (key[i] == '_')) {
+ if (EXPECTED(xhyphen && (key[i] == '_'))) {
key[i] = '-';
}
wasalpha = 0;
}
- ++i;
- );
+ }
}
return key;
}
if (flags & ARRAY_JOIN_STRINGIFY) {
convert_to_string_ex(value);
}
- Z_ADDREF_P(value);
+ Z_TRY_ADDREF_P(value);
if (data) {
if (Z_TYPE_P(data) != IS_ARRAY) {
zval zdata;
ZVAL_STRINGL(&zdata, str, len);
- if (SUCCESS == zend_fcall_info_argn(&fcd->fci, 2, &fcd->fcz, &zdata)) {
- zend_fcall_info_call(&fcd->fci, &fcd->fcc, NULL, NULL);
- zend_fcall_info_args_clear(&fcd->fci, 0);
- }
+ zend_fcall_info_argn(&fcd->fci, 2, &fcd->fcz, &zdata);
+ zend_fcall_info_call(&fcd->fci, &fcd->fcc, NULL, NULL);
+ zend_fcall_info_args_clear(&fcd->fci, 0);
zval_ptr_dtor(&zdata);
return len;
}