projects
/
m6w6
/
ext-http
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
|
github
raw
|
patch
|
inline
| side by side (parent:
650dad8
)
- tiny opt. bits
author
Michael Wallner
<mike@php.net>
Mon, 24 Apr 2006 17:17:09 +0000
(17:17 +0000)
committer
Michael Wallner
<mike@php.net>
Mon, 24 Apr 2006 17:17:09 +0000
(17:17 +0000)
phpstr/phpstr.c
patch
|
blob
|
history
diff --git
a/phpstr/phpstr.c
b/phpstr/phpstr.c
index addbf34362b369190227ec175ef614627e3c62d7..eb2f87a715d29d6975f0528e479ee81c18da9bac 100644
(file)
--- a/
phpstr/phpstr.c
+++ b/
phpstr/phpstr.c
@@
-212,7
+212,7
@@
PHPSTR_API phpstr *phpstr_sub(const phpstr *buf, size_t offset, size_t length)
if (offset >= buf->used) {
return NULL;
} else {
if (offset >= buf->used) {
return NULL;
} else {
- size_t need =
(length + offset) > buf->used ? (buf->used - offset) : (length - offset
);
+ size_t need =
1 + ((length + offset) > buf->used ? (buf->used - offset) : (length - offset)
);
phpstr *sub = phpstr_init_ex(NULL, need, PHPSTR_INIT_PREALLOC | (buf->pmem ? PHPSTR_INIT_PERSISTENT:0));
if (sub) {
if (PHPSTR_NOMEM == phpstr_append(sub, buf->data + offset, need)) {
phpstr *sub = phpstr_init_ex(NULL, need, PHPSTR_INIT_PREALLOC | (buf->pmem ? PHPSTR_INIT_PERSISTENT:0));
if (sub) {
if (PHPSTR_NOMEM == phpstr_append(sub, buf->data + offset, need)) {
@@
-326,7
+326,7
@@
PHPSTR_API size_t phpstr_chunk_buffer(phpstr **s, const char *data, size_t data_
*chunk = NULL;
if (!*s) {
*chunk = NULL;
if (!*s) {
- *s = phpstr_init_ex(NULL, chunk_size
* 2
, chunk_size ? PHPSTR_INIT_PREALLOC : 0);
+ *s = phpstr_init_ex(NULL, chunk_size
<< 1
, chunk_size ? PHPSTR_INIT_PREALLOC : 0);
}
storage = *s;
}
storage = *s;
@@
-340,12
+340,10
@@
PHPSTR_API size_t phpstr_chunk_buffer(phpstr **s, const char *data, size_t data_
return chunk_size;
}
return chunk_size;
}
- if (storage->used >= storage->size/2) {
- phpstr *avail = phpstr_left(storage, storage->size/2);
- *chunk = estrndup(PHPSTR_VAL(avail), PHPSTR_LEN(avail));
- phpstr_free(&avail);
- phpstr_cut(storage, 0, storage->size/2);
- return storage->size/2;
+ if (storage->used >= (chunk_size = storage->size >> 1)) {
+ *chunk = estrndup(storage->data, chunk_size);
+ phpstr_cut(storage, 0, chunk_size);
+ return chunk_size;
}
return 0;
}
return 0;