"Koda dievs",
jociigais cilveek Tu man centiisies ieskaidrot ka mashiinkoda operaacija - integer inkrements ir tikai 20 reizes aatraaks par rindas skaneeshanas un sastaavdalju paarsuutiishanas operaacijaam , dzekinj nokompilee uz c un paskaties kodu, varbuut tad tev naaks sapraats maajaas.
Jociigi laiki pienaakushi programmet saakushi visaadi rahiiti, kas c un vai asm nav redzeejushi un priekshstata par to kaa viss laaciitim veederaa notiek nav nekaada.
explode ir tuukstoshiem reizhu leenaaka nekaa $a=$a+1
taatad luuk, explode php funkcijas kods:
PHP_FUNCTION(explode)
{
zval **str, **delim, **zlimit = NULL;
int limit = -1;
int argc = ZEND_NUM_ARGS();
if (argc < 2 || argc > 3 || zend_get_parameters_ex(argc, &delim, &str, &zlimit) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string_ex(str);
convert_to_string_ex(delim);
if (argc > 2) {
convert_to_long_ex(zlimit);
limit = Z_LVAL_PP(zlimit);
}
if (! Z_STRLEN_PP(delim)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty delimiter");
RETURN_FALSE;
}
array_init(return_value);
if (! Z_STRLEN_PP(str)) {
if (limit >= 0 || argc == 2) {
add_next_index_stringl(return_value, "", sizeof("") - 1, 1);
}
return;
}
if (limit == 0 || limit == 1) {
add_index_stringl(return_value, 0, Z_STRVAL_PP(str), Z_STRLEN_PP(str), 1);
} else if (limit < 0 && argc == 3) {
php_explode_negative_limit(*delim, *str, return_value, limit);
} else {
php_explode(*delim, *str, return_value, limit);
}
}
PHPAPI void php_explode(zval *delim, zval *str, zval *return_value, int limit)
{
char *p1, *p2, *endp;
endp = Z_STRVAL_P(str) + Z_STRLEN_P(str);
p1 = Z_STRVAL_P(str);
p2 = php_memnstr(Z_STRVAL_P(str), Z_STRVAL_P(delim), Z_STRLEN_P(delim), endp);
if (p2 == NULL) {
add_next_index_stringl(return_value, p1, Z_STRLEN_P(str), 1);
} else {
do {
add_next_index_stringl(return_value, p1, p2 - p1, 1);
p1 = p2 + Z_STRLEN_P(delim);
} while ((p2 = php_memnstr(p1, Z_STRVAL_P(delim), Z_STRLEN_P(delim), endp)) != NULL &&
(limit == -1 || --limit > 1));
if (p1 <= endp)
add_next_index_stringl(return_value, p1, endp-p1, 1);
}
}
PHPAPI void php_explode_negative_limit(zval *delim, zval *str, zval *return_value, int limit)
{
#define EXPLODE_ALLOC_STEP 50
char *p1, *p2, *endp;
int allocated = EXPLODE_ALLOC_STEP, found = 0, i = 0, to_return = 0;
char **positions = safe_emalloc(allocated, sizeof(char *), 0);
endp = Z_STRVAL_P(str) + Z_STRLEN_P(str);
p1 = Z_STRVAL_P(str);
p2 = php_memnstr(Z_STRVAL_P(str), Z_STRVAL_P(delim), Z_STRLEN_P(delim), endp);
if (p2 == NULL) {
/*
do nothing since limit <= -1, thus if only one chunk - 1 + (limit) <= 0
by doing nothing we return empty array
*/
} else {
positions[found++] = p1;
do {
if (found >= allocated) {
allocated = found + EXPLODE_ALLOC_STEP;/* make sure we have enough memory */
positions = erealloc(positions, allocated*sizeof(char *));
}
positions[found++] = p1 = p2 + Z_STRLEN_P(delim);
} while ((p2 = php_memnstr(p1, Z_STRVAL_P(delim), Z_STRLEN_P(delim), endp)) != NULL);
to_return = limit + found;
/* limit is at least -1 therefore no need of bounds checking : i will be always less than found */
for (i = 0;i < to_return;i++) { /* this checks also for to_return > 0 */
add_next_index_stringl(return_value, positions,
(positions[i+1] - Z_STRLEN_P(delim)) - positions,
1
);
}
}
efree(positions);
#undef EXPLODE_ALLOC_STEP
}
Un tagad saliidzini visu sho blaakji ar vienu inkrementa operaaciju: a++;