diff options
author | Greg Stein <gstein@apache.org> | 2001-04-27 05:27:00 +0000 |
---|---|---|
committer | Greg Stein <gstein@apache.org> | 2001-04-27 05:27:00 +0000 |
commit | 8271967b17a72ffd747f0a68490953a4582c563d (patch) | |
tree | 18d78cfe2aa9ff00632c01fc8415928fdc1fa46f | |
parent | f706c5a618c84d1acb96048ce9a568fc79f0bfff (diff) | |
download | httpd-8271967b17a72ffd747f0a68490953a4582c563d.tar.gz |
fast-path some cases, primarily to avoid an allocation when it isn't needed.
for a "nice" piece of cdata which is in one chunk, this can usually avoid an
allocation.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@88943 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | modules/dav/main/util.c | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/modules/dav/main/util.c b/modules/dav/main/util.c index cc21a836f9..741af53ba0 100644 --- a/modules/dav/main/util.c +++ b/modules/dav/main/util.c @@ -334,15 +334,36 @@ const char *dav_xml_get_cdata(const ap_xml_elem *elem, apr_pool_t *pool, char *cdata; char *s; apr_size_t tlen; + const char *found_text; + int found_count = 0; - for (scan = elem->first_cdata.first; scan != NULL; scan = scan->next) - len += strlen(scan->text); + for (scan = elem->first_cdata.first; scan != NULL; scan = scan->next) { + found_text = scan->text; + ++found_count; + len += strlen(found_text); + } for (child = elem->first_child; child != NULL; child = child->next) { for (scan = child->following_cdata.first; scan != NULL; - scan = scan->next) - len += strlen(scan->text); + scan = scan->next) { + found_text = scan->text; + ++found_count; + len += strlen(found_text); + } + } + + /* some fast-path cases: + * 1) zero-length cdata + * 2) a single piece of cdata with no whitespace to strip + */ + if (len == 0) + return ""; + if (found_count == 1) { + if (!strip_white + || (!apr_isspace(*found_text) + && !apr_isspace(found_text[len - 1]))) + return found_text; } cdata = s = apr_palloc(pool, len + 1); @@ -365,7 +386,7 @@ const char *dav_xml_get_cdata(const ap_xml_elem *elem, apr_pool_t *pool, *s = '\0'; - if (strip_white && len > 0) { + if (strip_white) { /* trim leading whitespace */ while (apr_isspace(*cdata)) /* assume: return false for '\0' */ ++cdata; |