At 21:40 10.02.2003, Moriyoshi Koizumi wrote:
[EMAIL PROTECTED] (Marcus Börger) wrote:
> Why not use spprintf before you make it even more complex?
> Something like this:
>
> if(!strstr(lower_temp,"realm")) {
>          efree(result);
>          spprintf(&result, 0, "%s realm=\"%ld\"",ptr, myuid);
> }

Because spprintf is just considerably s..l..o..w...

I always prefer to avoid using that function as long as I can reasonably
estimate the length of result in advance.

Moriyoshi
Ah, Ok then. I see i should have made spprintf's interface to support
an estimated size....but then !! i see the real problem here, i overlooked
it when rewriting the stuff....yes it is really!! slow....but how about this
change:

cvs -z3 -q diff spprintf.c (in directory S:\php4-HEAD\main\)
Index: spprintf.c
===================================================================
RCS file: /repository/php4/main/spprintf.c,v
retrieving revision 1.11
diff -u -r1.11 spprintf.c
--- spprintf.c 31 Dec 2002 15:58:54 -0000 1.11
+++ spprintf.c 10 Feb 2003 21:19:46 -0000
@@ -177,6 +177,21 @@
cc++; \
}

+#define INS_STRING(xbuf, s, slen, cc) \
+ xbuf_resize(xbuf, s_len); \
+ if (xbuf->nextb+slen < xbuf->buf_end) { \
+ fprintf(stderr, "Using(%d); '%s'\n", slen, s);\
+ memcpy(xbuf->nextb, s, slen); \
+ xbuf->nextb += slen; \
+ cc += slen; \
+ s += slen; \
+ } else { \
+ for (i = s_len; i != 0; i--) { \
+ INS_CHAR_NR(xbuf, *s, cc); \
+ s++; \
+ } \
+ }
+
#define INS_CHAR(xbuf, ch, cc) \
xbuf_resize(xbuf, 1); \
INS_CHAR_NR(xbuf, ch, cc)
@@ -582,11 +597,7 @@
/*
* Print the string s.
*/
- xbuf_resize(xbuf, s_len);
- for (i = s_len; i != 0; i--) {
- INS_CHAR_NR(xbuf, *s, cc);
- s++;
- }
+ INS_STRING(xbuf, s, s_len, cc);

if (adjust_width && adjust == LEFT && min_width > s_len)
PAD(xbuf, min_width, s_len, pad_char);


This should besides some aditional setup in abot two additional function calls basically
do the same then the typical strlen, strlen, malloc, memcpy, memcpy, s[x]=0 stuff.

regards
marcus



--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to