Based on OtherBill's suggestion to differentiate the name, this
update to the patch creates the faster string-dup function as
apr_pstrmemdup() (a hybrid of strdup and memdup) rather than
apr_pstrdupn().
--Brian
Index: srclib/apr/include/apr_strings.h
===================================================================
RCS file: /home/cvspublic/apr/include/apr_strings.h,v
retrieving revision 1.22
diff -u -r1.22 apr_strings.h
--- srclib/apr/include/apr_strings.h 2001/08/24 17:55:45 1.22
+++ srclib/apr/include/apr_strings.h 2001/12/02 08:41:48
@@ -128,6 +128,20 @@
APR_DECLARE(char *) apr_pstrdup(apr_pool_t *p, const char *s);
/**
+ * Create a null-terminated string by making a copy of a sequence
+ * of characters and appending a null byte
+ * @param p The pool to allocate out of
+ * @param s The block of characters to duplicate
+ * @param n The number of characters to duplicate
+ * @return The new string
+ * @remark This is a faster alternative to apr_pstrndup, for use
+ * when you know that the string being duplicated really
+ * has 'n' or more characters. If the string might contain
+ * fewer characters, use apr_pstrndup.
+ */
+APR_DECLARE(char *) apr_pstrmemdup(apr_pool_t *p, const char *s, apr_size_t n);
+
+/**
* duplicate the first n characters of a string into memory allocated
* out of a pool; the new string will be '\0'-terminated
* @param p The pool to allocate out of
Index: srclib/apr/strings/apr_strings.c
===================================================================
RCS file: /home/cvspublic/apr/strings/apr_strings.c,v
retrieving revision 1.22
diff -u -r1.22 apr_strings.c
--- srclib/apr/strings/apr_strings.c 2001/09/28 04:11:20 1.22
+++ srclib/apr/strings/apr_strings.c 2001/12/02 08:41:48
@@ -99,6 +99,19 @@
return res;
}
+APR_DECLARE(char *) apr_pstrmemdup(apr_pool_t *a, const char *s, apr_size_t n)
+{
+ char *res;
+
+ if (s == NULL) {
+ return NULL;
+ }
+ res = apr_palloc(a, n + 1);
+ memcpy(res, s, n);
+ res[n] = '\0';
+ return res;
+}
+
APR_DECLARE(void *) apr_pmemdup(apr_pool_t *a, const void *m, apr_size_t n)
{
void *res;
Index: srclib/apr-util/uri/apr_uri.c
===================================================================
RCS file: /home/cvspublic/apr-util/uri/apr_uri.c,v
retrieving revision 1.10
diff -u -r1.10 apr_uri.c
--- srclib/apr-util/uri/apr_uri.c 2001/08/19 16:06:57 1.10
+++ srclib/apr-util/uri/apr_uri.c 2001/12/02 08:41:48
@@ -246,7 +246,7 @@
++s;
}
if (s != uri) {
- uptr->path = apr_pstrndup(p, uri, s - uri);
+ uptr->path = apr_pstrmemdup(p, uri, s - uri);
}
if (*s == 0) {
return APR_SUCCESS;
@@ -256,7 +256,7 @@
s1 = strchr(s, '#');
if (s1) {
uptr->fragment = apr_pstrdup(p, s1 + 1);
- uptr->query = apr_pstrndup(p, s, s1 - s);
+ uptr->query = apr_pstrmemdup(p, s, s1 - s);
}
else {
uptr->query = apr_pstrdup(p, s);
@@ -278,14 +278,14 @@
goto deal_with_path; /* backwards predicted taken! */
}
- uptr->scheme = apr_pstrndup(p, uri, s - uri);
+ uptr->scheme = apr_pstrmemdup(p, uri, s - uri);
s += 3;
hostinfo = s;
while ((uri_delims[*(unsigned char *)s] & NOTEND_HOSTINFO) == 0) {
++s;
}
uri = s; /* whatever follows hostinfo is start of uri */
- uptr->hostinfo = apr_pstrndup(p, hostinfo, uri - hostinfo);
+ uptr->hostinfo = apr_pstrmemdup(p, hostinfo, uri - hostinfo);
/* If there's a username:[EMAIL PROTECTED]:port, the @ we want is the last
@...
* too bad there's no memrchr()... For the C purists, note that hostinfo
@@ -304,12 +304,12 @@
s = memchr(hostinfo, ':', uri - hostinfo);
if (s == NULL) {
/* we expect the common case to have no port */
- uptr->hostname = apr_pstrndup(p, hostinfo, uri - hostinfo);
+ uptr->hostname = apr_pstrmemdup(p, hostinfo, uri - hostinfo);
goto deal_with_path;
}
- uptr->hostname = apr_pstrndup(p, hostinfo, s - hostinfo);
+ uptr->hostname = apr_pstrmemdup(p, hostinfo, s - hostinfo);
++s;
- uptr->port_str = apr_pstrndup(p, s, uri - s);
+ uptr->port_str = apr_pstrmemdup(p, s, uri - s);
if (uri != s) {
port = strtol(uptr->port_str, &endstr, 10);
uptr->port = port;
@@ -326,12 +326,12 @@
/* first colon delimits username:password */
s1 = memchr(hostinfo, ':', s - hostinfo);
if (s1) {
- uptr->user = apr_pstrndup(p, hostinfo, s1 - hostinfo);
+ uptr->user = apr_pstrmemdup(p, hostinfo, s1 - hostinfo);
++s1;
- uptr->password = apr_pstrndup(p, s1, s - s1);
+ uptr->password = apr_pstrmemdup(p, s1, s - s1);
}
else {
- uptr->user = apr_pstrndup(p, hostinfo, s - hostinfo);
+ uptr->user = apr_pstrmemdup(p, hostinfo, s - hostinfo);
}
hostinfo = s + 1;
goto deal_with_host;