manoj 99/04/16 20:06:39
Modified: pthreads/src/main util.c
Log:
Optimize ap_gm_timestr_822, ap_make_dirstr_prefix, and ap_unescape_url.
Revision Changes Path
1.4 +60 -15 apache-apr/pthreads/src/main/util.c
Index: util.c
===================================================================
RCS file: /home/cvs/apache-apr/pthreads/src/main/util.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -u -r1.3 -r1.4
--- util.c 1999/03/17 17:01:23 1.3
+++ util.c 1999/04/17 03:06:38 1.4
@@ -173,14 +173,56 @@
API_EXPORT(char *) ap_gm_timestr_822(pool *p, time_t sec)
{
struct tm *tms;
+ char *date_str = ap_palloc(p, 48 * sizeof(char));
+ char *date_str_ptr = date_str;
+ int real_year;
tms = gmtime(&sec); /* ZZZ replace with AP time routine */
+ /* Assumption: this is always 3 */
+ /* i = strlen(ap_day_snames[tms->tm_wday]); */
+ memcpy(date_str_ptr, ap_day_snames[tms->tm_wday], 3);
+ date_str_ptr += 3;
+ *date_str_ptr++ = ',';
+ *date_str_ptr++ = ' ';
+ *date_str_ptr++ = tms->tm_mday / 10 + '0';
+ *date_str_ptr++ = tms->tm_mday % 10 + '0';
+ *date_str_ptr++ = ' ';
+ /* Assumption: this is also always 3 */
+ /* i = strlen(ap_month_snames[tms->tm_mon]); */
+ memcpy(date_str_ptr, ap_month_snames[tms->tm_mon], 3);
+ date_str_ptr += 3;
+ *date_str_ptr++ = ' ';
+ real_year = 1900 + tms->tm_year;
+ /* This routine isn't y10k ready. */
+ *date_str_ptr++ = real_year / 1000 + '0';
+ *date_str_ptr++ = real_year % 1000 / 100 + '0';
+ *date_str_ptr++ = real_year % 100 / 10 + '0';
+ *date_str_ptr++ = real_year % 10 + '0';
+ *date_str_ptr++ = ' ';
+ *date_str_ptr++ = tms->tm_hour / 10 + '0';
+ *date_str_ptr++ = tms->tm_hour % 10 + '0';
+ *date_str_ptr++ = ':';
+ *date_str_ptr++ = tms->tm_min / 10 + '0';
+ *date_str_ptr++ = tms->tm_min % 10 + '0';
+ *date_str_ptr++ = ':';
+ *date_str_ptr++ = tms->tm_sec / 10 + '0';
+ *date_str_ptr++ = tms->tm_sec % 10 + '0';
+ *date_str_ptr++ = ' ';
+ *date_str_ptr++ = 'G';
+ *date_str_ptr++ = 'M';
+ *date_str_ptr++ = 'T';
+ *date_str_ptr = '\0';
+
+ return date_str;
/* RFC date format; as strftime '%a, %d %b %Y %T GMT' */
+
+ /* The equivalent using sprintf. Use this for more legible but slower
code
return ap_psprintf(p,
"%s, %.2d %s %d %.2d:%.2d:%.2d GMT",
ap_day_snames[tms->tm_wday],
tms->tm_mday, ap_month_snames[tms->tm_mon], tms->tm_year + 1900,
tms->tm_hour, tms->tm_min, tms->tm_sec);
+ */
}
/* What a pain in the ass. */
@@ -472,15 +514,11 @@
API_EXPORT(char *) ap_make_dirstr_prefix(char *d, const char *s, int n)
{
for (;;) {
- *d = *s;
- if (*d == '\0') {
+ if (*s == '\0' || (*s == '/' && (--n) == 0)) {
*d = '/';
break;
}
- if (*d == '/' && (--n) == 0)
- break;
- ++d;
- ++s;
+ *d++ = *s++;
}
*++d = 0;
return (d);
@@ -1395,27 +1433,34 @@
*/
API_EXPORT(int) ap_unescape_url(char *url)
{
- register int x, y, badesc, badpath;
+ register int badesc, badpath;
+ char *x, *y;
badesc = 0;
badpath = 0;
- for (x = 0, y = 0; url[y]; ++x, ++y) {
- if (url[y] != '%')
- url[x] = url[y];
+ /* Initial scan for first '%'. Don't bother writing values before
+ * seeing a '%' */
+ y = strchr(url, '%');
+ if (y == NULL) {
+ return OK;
+ }
+ for (x = y; *y; ++x, ++y) {
+ if (*y != '%')
+ *x = *y;
else {
- if (!ap_isxdigit(url[y + 1]) || !ap_isxdigit(url[y + 2])) {
+ if (!ap_isxdigit(*(y + 1)) || !ap_isxdigit(*(y + 2))) {
badesc = 1;
- url[x] = '%';
+ *x = '%';
}
else {
- url[x] = x2c(&url[y + 1]);
+ *x = x2c(y + 1);
y += 2;
- if (url[x] == '/' || url[x] == '\0')
+ if (*x == '/' || *x == '\0')
badpath = 1;
}
}
}
- url[x] = '\0';
+ *x = '\0';
if (badesc)
return BAD_REQUEST;
else if (badpath)