You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by gs...@apache.org on 2012/03/19 20:12:44 UTC

svn commit: r1302604 - in /subversion/trunk/subversion/libsvn_ra_serf: blame.c getdate.c options.c property.c

Author: gstein
Date: Mon Mar 19 19:12:44 2012
New Revision: 1302604

URL: http://svn.apache.org/viewvc?rev=1302604&view=rev
Log:
Start getting rid of svn_ra_serf__expand_string() by using stringbufs.

* subversion/libsvn_ra_serf/getdate.c:
  (date_info_t): no longer needed
  (date_context_t): no need to save a pool
  (push_state): removed. folded into start_getdate()
  (start_getdate): initialize a stringbuf to collect cdata
  (end_getdate): get the contents from the stringbuf
  (cdata_getdate): append the cdata to the stringbuf
  (svn_ra_serf__get_dated_revision): no need to save the pool into the
    context, and we can skip the calloc.

* subversion/libsvn_ra_serf/property.c:
  (prop_info_t): use a stringbuf rather than val/val_len.
  (push_state): initialize an empty stringbuf for contents
  (start_propfind): no need to copy "href" (which has permanent life)
  (end_propfind): fetch the value out of the stringbuf
  (cdata_propfind): append the cdata to the stringbuf

* subversion/libsvn_ra_serf/blame.c:
  (blame_info_t): use a stringbuf rather than prop_attr/_len.
  (push_state): use calloc to zero out the info. allocate an empty
    stringbuf for accumulating cdata
  (create_propval): return the appropriate (decoded) value
  (start_blame): reset the stringbuf to empty for accumulation
  (cdata_blame): append the cdata to the stringbuf

* subversion/libsvn_ra_serf/options.c:
  (svn_ra_serf__options_context_t): use a stringbuf to accumulate the
    activity-collection value
  (end_options): use the value saved in the stringbuf
  (cdata_options): append the cdata to the stringbuf
  (svn_ra_serf__create_options_req): initialize the stringbuf

Modified:
    subversion/trunk/subversion/libsvn_ra_serf/blame.c
    subversion/trunk/subversion/libsvn_ra_serf/getdate.c
    subversion/trunk/subversion/libsvn_ra_serf/options.c
    subversion/trunk/subversion/libsvn_ra_serf/property.c

Modified: subversion/trunk/subversion/libsvn_ra_serf/blame.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/blame.c?rev=1302604&r1=1302603&r2=1302604&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/blame.c (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/blame.c Mon Mar 19 19:12:44 2012
@@ -39,6 +39,8 @@
 
 #include "svn_private_config.h"
 
+#include "private/svn_string_private.h"
+
 #include "ra_serf.h"
 #include "../libsvn_ra/ra_loader.h"
 
@@ -85,10 +87,7 @@ typedef struct blame_info_t {
 
   /* The currently collected value as we build it up */
   const char *prop_name;
-  const char *prop_attr;
-  apr_size_t prop_attr_len;
-
-  svn_string_t *prop_string;
+  svn_stringbuf_t *prop_value;
 
   /* Merged revision flag */
   svn_boolean_t merged_revision;
@@ -125,18 +124,16 @@ push_state(svn_ra_serf__xml_parser_t *pa
     {
       blame_info_t *info;
 
-      info = apr_palloc(parser->state->pool, sizeof(*info));
+      info = apr_pcalloc(parser->state->pool, sizeof(*info));
 
       info->pool = parser->state->pool;
 
       info->rev = SVN_INVALID_REVNUM;
-      info->path = NULL;
 
       info->rev_props = apr_hash_make(info->pool);
       info->prop_diffs = apr_array_make(info->pool, 0, sizeof(svn_prop_t));
 
-      info->stream = NULL;
-      info->merged_revision = FALSE;
+      info->prop_value = svn_stringbuf_create_empty(info->pool);
 
       parser->state->private = info;
     }
@@ -147,24 +144,15 @@ push_state(svn_ra_serf__xml_parser_t *pa
 static const svn_string_t *
 create_propval(blame_info_t *info)
 {
-  const svn_string_t *s;
-
-  if (!info->prop_attr)
-    {
-      return svn_string_create_empty(info->pool);
-    }
-  else
-    {
-      info->prop_attr = apr_pmemdup(info->pool, info->prop_attr,
-                                    info->prop_attr_len + 1);
-    }
-
-  s = svn_string_ncreate(info->prop_attr, info->prop_attr_len, info->pool);
   if (info->prop_base64)
     {
-      s = svn_base64_decode_string(s, info->pool);
+      const svn_string_t *morph;
+
+      morph = svn_stringbuf__morph_into_string(info->prop_value);
+      return svn_base64_decode_string(morph, info->pool);
     }
-  return s;
+
+  return svn_string_create_from_buf(info->prop_value, info->pool);
 }
 
 static svn_error_t *
@@ -240,8 +228,7 @@ start_blame(svn_ra_serf__xml_parser_t *p
         case REMOVE_PROP:
           info->prop_name = apr_pstrdup(info->pool,
                                         svn_xml_get_attr_value("name", attrs));
-          info->prop_attr = NULL;
-          info->prop_attr_len = 0;
+          svn_stringbuf_setempty(info->prop_value);
 
           enc = svn_xml_get_attr_value("encoding", attrs);
           if (enc && strcmp(enc, "base64") == 0)
@@ -360,8 +347,7 @@ cdata_blame(svn_ra_serf__xml_parser_t *p
     {
       case REV_PROP:
       case SET_PROP:
-        svn_ra_serf__expand_string(&info->prop_attr, &info->prop_attr_len,
-                                   data, len, parser->state->pool);
+        svn_stringbuf_appendbytes(info->prop_value, data, len);
         break;
       case TXDELTA:
         if (info->stream)

Modified: subversion/trunk/subversion/libsvn_ra_serf/getdate.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/getdate.c?rev=1302604&r1=1302603&r2=1302604&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/getdate.c (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/getdate.c Mon Mar 19 19:12:44 2012
@@ -51,15 +51,8 @@ typedef enum date_state_e {
   VERSION_NAME
 } date_state_e;
 
-typedef struct date_info_t {
-  /* The currently collected value as we build it up */
-  const char *tmp;
-  apr_size_t tmp_len;
-} date_info_t;
 
 typedef struct date_context_t {
-  apr_pool_t *pool;
-
   /* The time asked about. */
   apr_time_t time;
 
@@ -71,25 +64,6 @@ typedef struct date_context_t {
 
 } date_context_t;
 
-
-static date_info_t *
-push_state(svn_ra_serf__xml_parser_t *parser,
-           date_context_t *date_ctx,
-           date_state_e state)
-{
-  svn_ra_serf__xml_push_state(parser, state);
-
-  if (state == VERSION_NAME)
-    {
-      date_info_t *info;
-
-      info = apr_pcalloc(parser->state->pool, sizeof(*info));
-
-      parser->state->private = info;
-    }
-
-  return parser->state->private;
-}
 
 static svn_error_t *
 start_getdate(svn_ra_serf__xml_parser_t *parser,
@@ -98,14 +72,16 @@ start_getdate(svn_ra_serf__xml_parser_t 
               const char **attrs)
 {
   date_context_t *date_ctx = userData;
-  date_state_e state;
+  date_state_e state = parser->state->current_state;
 
-  state = parser->state->current_state;
+  UNUSED_CTX(date_ctx);
 
   if (state == NONE &&
       strcmp(name.name, SVN_DAV__VERSION_NAME) == 0)
     {
-      push_state(parser, date_ctx, VERSION_NAME);
+      svn_ra_serf__xml_push_state(parser, VERSION_NAME);
+
+      parser->state->private = svn_stringbuf_create_empty(parser->state->pool);
     }
 
   return SVN_NO_ERROR;
@@ -117,16 +93,14 @@ end_getdate(svn_ra_serf__xml_parser_t *p
             svn_ra_serf__dav_props_t name)
 {
   date_context_t *date_ctx = userData;
-  date_state_e state;
-  date_info_t *info;
-
-  state = parser->state->current_state;
-  info = parser->state->private;
+  date_state_e state = parser->state->current_state;
 
   if (state == VERSION_NAME &&
       strcmp(name.name, SVN_DAV__VERSION_NAME) == 0)
     {
-      *date_ctx->revision = SVN_STR_TO_REV(info->tmp);
+      const svn_stringbuf_t *datebuf = parser->state->private;
+
+      *date_ctx->revision = SVN_STR_TO_REV(datebuf->data);
       svn_ra_serf__xml_pop_state(parser);
     }
 
@@ -140,19 +114,16 @@ cdata_getdate(svn_ra_serf__xml_parser_t 
               apr_size_t len)
 {
   date_context_t *date_ctx = userData;
-  date_state_e state;
-  date_info_t *info;
+  date_state_e state = parser->state->current_state;
+  svn_stringbuf_t *datebuf;
 
   UNUSED_CTX(date_ctx);
 
-  state = parser->state->current_state;
-  info = parser->state->private;
-
   switch (state)
     {
     case VERSION_NAME:
-        svn_ra_serf__expand_string(&info->tmp, &info->tmp_len,
-                                   data, len, parser->state->pool);
+        datebuf = parser->state->private;
+        svn_stringbuf_appendbytes(datebuf, data, len);
         break;
     default:
         break;
@@ -202,8 +173,7 @@ svn_ra_serf__get_dated_revision(svn_ra_s
   const char *report_target;
   int status_code;
 
-  date_ctx = apr_pcalloc(pool, sizeof(*date_ctx));
-  date_ctx->pool = pool;
+  date_ctx = apr_palloc(pool, sizeof(*date_ctx));
   date_ctx->time = tm;
   date_ctx->revision = revision;
   date_ctx->done = FALSE;

Modified: subversion/trunk/subversion/libsvn_ra_serf/options.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/options.c?rev=1302604&r1=1302603&r2=1302604&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/options.c (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/options.c Mon Mar 19 19:12:44 2012
@@ -66,8 +66,8 @@ struct svn_ra_serf__options_context_t {
   /* pool to allocate memory from */
   apr_pool_t *pool;
 
-  const char *attr_val;
-  apr_size_t attr_val_len;
+  /* Buffer for the activity-collection  */
+  svn_stringbuf_t *acbuf;
   svn_boolean_t collect_cdata;
 
   /* Current state we're in */
@@ -187,7 +187,7 @@ end_options(svn_ra_serf__xml_parser_t *p
     {
       options_ctx->collect_cdata = FALSE;
       options_ctx->activity_collection =
-        svn_urlpath__canonicalize(options_ctx->attr_val, options_ctx->pool);
+        svn_urlpath__canonicalize(options_ctx->acbuf->data, options_ctx->pool);
       pop_state(options_ctx);
     }
 
@@ -201,11 +201,9 @@ cdata_options(svn_ra_serf__xml_parser_t 
               apr_size_t len)
 {
   svn_ra_serf__options_context_t *ctx = userData;
+
   if (ctx->collect_cdata)
-    {
-      svn_ra_serf__expand_string(&ctx->attr_val, &ctx->attr_val_len,
-                                 data, len, ctx->pool);
-    }
+    svn_stringbuf_appendbytes(ctx->acbuf, data, len);
 
   return SVN_NO_ERROR;
 }
@@ -442,6 +440,8 @@ svn_ra_serf__create_options_req(svn_ra_s
 
   new_ctx->pool = pool;
 
+  new_ctx->acbuf = svn_stringbuf_create_empty(pool);
+
   new_ctx->path = path;
   new_ctx->youngest_rev = SVN_INVALID_REVNUM;
 

Modified: subversion/trunk/subversion/libsvn_ra_serf/property.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/property.c?rev=1302604&r1=1302603&r2=1302604&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/property.c (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/property.c Mon Mar 19 19:12:44 2012
@@ -33,6 +33,7 @@
 
 #include "private/svn_dav_protocol.h"
 #include "private/svn_fspath.h"
+#include "private/svn_string_private.h"
 #include "svn_private_config.h"
 
 #include "ra_serf.h"
@@ -51,11 +52,8 @@ typedef struct prop_info_t {
 
   /* Current ns, attribute name, and value of the property we're parsing */
   const char *ns;
-
   const char *name;
-
-  const char *val;
-  apr_size_t val_len;
+  svn_stringbuf_t *value;
 
   const char *encoding;
 
@@ -243,6 +241,7 @@ push_state(svn_ra_serf__xml_parser_t *pa
 
       info = apr_pcalloc(parser->state->pool, sizeof(*info));
       info->pool = parser->state->pool;
+      info->value = svn_stringbuf_create_empty(info->pool);
 
       parser->state->private = info;
     }
@@ -273,7 +272,7 @@ start_propfind(svn_ra_serf__xml_parser_t
     {
       info = push_state(parser, ctx, PROPVAL);
       info->ns = name.namespace;
-      info->name = apr_pstrdup(info->pool, name.name);
+      info->name = "href";
     }
   else if (state == RESPONSE && strcmp(name.name, "prop") == 0)
     {
@@ -316,24 +315,20 @@ end_propfind(svn_ra_serf__xml_parser_t *
     }
   else if (state == PROPVAL)
     {
-      const char *ns, *pname, *val;
-      svn_string_t *val_str;
+      const char *ns;
+      const char *pname;
+      const svn_string_t *val_str = NULL;
 
       /* if we didn't see a CDATA element, we may want the tag name
        * as long as it isn't equivalent to the property name.
        */
-      if (!info->val)
+      /* ### gstein sez: I have no idea what this is about.  */
+      if (*info->value->data == '\0')
         {
           if (strcmp(info->name, name.name) != 0)
-            {
-              info->val = name.name;
-              info->val_len = strlen(info->val);
-            }
+            val_str = svn_string_create(name.name, ctx->pool);
           else
-            {
-              info->val = "";
-              info->val_len = 0;
-            }
+            val_str = svn_string_create_empty(ctx->pool);
         }
 
       if (parser->state->prev->current_state == RESPONSE &&
@@ -342,7 +337,7 @@ end_propfind(svn_ra_serf__xml_parser_t *
           if (strcmp(ctx->depth, "1") == 0)
             {
               ctx->current_path =
-                svn_urlpath__canonicalize(info->val, ctx->pool);
+                svn_urlpath__canonicalize(info->value->data, ctx->pool);
             }
           else
             {
@@ -353,15 +348,10 @@ end_propfind(svn_ra_serf__xml_parser_t *
         {
           if (strcmp(info->encoding, "base64") == 0)
             {
-              svn_string_t encoded;
-              const svn_string_t *decoded;
-
-              encoded.data = info->val;
-              encoded.len = info->val_len;
+              const svn_string_t *morph;
 
-              decoded = svn_base64_decode_string(&encoded, parser->state->pool);
-              info->val = decoded->data;
-              info->val_len = decoded->len;
+              morph = svn_stringbuf__morph_into_string(info->value);
+              val_str = svn_base64_decode_string(morph, ctx->pool);
             }
           else
             {
@@ -372,10 +362,13 @@ end_propfind(svn_ra_serf__xml_parser_t *
             }
         }
 
+      /* ### there may be better logic to ensure this is set above, but just
+         ### going for the easy win here.  */
+      if (val_str == NULL)
+        val_str = svn_string_create_from_buf(info->value, ctx->pool);
+
       ns = apr_pstrdup(ctx->pool, info->ns);
       pname = apr_pstrdup(ctx->pool, info->name);
-      val = apr_pmemdup(ctx->pool, info->val, info->val_len);
-      val_str = svn_string_ncreate(val, info->val_len, ctx->pool);
 
       /* set the return props and update our cache too. */
       svn_ra_serf__set_ver_prop(ctx->ret_props,
@@ -410,10 +403,7 @@ cdata_propfind(svn_ra_serf__xml_parser_t
   info = parser->state->private;
 
   if (state == PROPVAL)
-    {
-      svn_ra_serf__expand_string(&info->val, &info->val_len, data, len,
-                                 info->pool);
-    }
+    svn_stringbuf_appendbytes(info->value, data, len);
 
   return SVN_NO_ERROR;
 }