On Wed, Mar 25, 2009 at 07:33, Senthil Kumaran S <senthil_at_collab.net> wrote:
>...
> +++ trunk/subversion/libsvn_client/add.c     Tue Mar 24 23:33:35 2009     (r36763)
> @@ -82,6 +82,51 @@ trim_string(char **pstr)
> Â str[i] = '\0';
> Â }
>
> +/* Split PROPERTY and store each individual value in PROPS.
> + Â Allocates from POOL. */
> +static void
> +split_props(apr_array_header_t **props,
> + Â Â Â Â Â Â const char *property,
> + Â Â Â Â Â Â apr_pool_t *pool)
> +{
> + Â apr_array_header_t *temp_props;
> + Â char *new_prop;
> + Â char *prop;
> + Â int i = 0;
> + Â int j = 0;
> +
> + Â temp_props = apr_array_make(pool, 4, sizeof(const char *));
> + Â new_prop = apr_palloc(pool, strlen(property));
allocate strlen(property)+1 .. with the suggested changes below, this
buffer will be used for all the results, and you may need the +1 to
store a NUL terminator.
> +
> + Â for (i = 0; i <= strlen(property); i++)
for (i = 0; property[i] != '\0'; i++)
would be better: you don't have to compute strlen() every iteration.
> + Â Â {
> + Â Â Â if (property[i] != ';')
> + Â Â Â Â {
> + Â Â Â Â Â new_prop[j] = property[i];
> + Â Â Â Â Â j++;
> + Â Â Â Â }
> + Â Â Â else if (property[i] == ';')
> + Â Â Â Â {
> + Â Â Â Â Â if (property[i+1] == ';')
> + Â Â Â Â Â Â {
> + Â Â Â Â Â Â Â new_prop[j] = property[i];
new_prop[j] = ';';
we already know its value, so a constant is better.
> + Â Â Â Â Â Â Â j++;
> + Â Â Â Â Â Â Â i++;
> + Â Â Â Â Â Â }
> + Â Â Â Â Â else
> + Â Â Â Â Â Â {
> + Â Â Â Â Â Â Â new_prop[j] = '\0';
> + Â Â Â Â Â Â Â prop = apr_palloc(pool, j+1);
> + Â Â Â Â Â Â Â j = 0;
> + Â Â Â Â Â Â strcpy(prop, new_prop);
> + Â Â Â Â Â Â Â APR_ARRAY_PUSH(temp_props, const char *) = prop;
there is no need to make an extra copy. you've allocated modifiable
memory already. just do the following:
new_prop[j] = '\0';
APR_ARRAY_PUSH(temp_props, const char *) = new_prop;
new_prop += j + 1;
j = 0;
> + Â Â Â Â Â Â }
> + Â Â Â }
> + Â Â }
> + Â APR_ARRAY_PUSH(temp_props, const char *) = new_prop;
> + Â *props = temp_props;
> +}
> +
> Â /* For one auto-props config entry (NAME, VALUE), if the filename pattern
> Â Â NAME matches BATON->filename case insensitively then add the properties
> Â Â listed in VALUE into BATON->properties.
> @@ -93,9 +138,9 @@ auto_props_enumerator(const char *name,
> Â Â Â Â Â Â Â Â Â Â Â void *baton,
> Â Â Â Â Â Â Â Â Â Â Â apr_pool_t *pool)
> Â {
> + Â int i;
> Â auto_props_baton_t *autoprops = baton;
> - Â char *property;
> - Â char *last_token;
> + Â apr_array_header_t *props;
>
> Â /* nothing to do here without a value */
> Â if (strlen(value) == 0)
> @@ -105,41 +150,44 @@ auto_props_enumerator(const char *name,
> Â if (apr_fnmatch(name, autoprops->filename, APR_FNM_CASE_BLIND) == APR_FNM_NOMATCH)
> Â Â return TRUE;
>
> - Â /* parse the value (we dup it first to effectively lose the
> - Â Â 'const', and to avoid messing up the original value) */
> - Â property = apr_pstrdup(autoprops->pool, value);
> - Â property = apr_strtok(property, ";", &last_token);
> - Â while (property)
> + Â props = apr_array_make(pool, 4, sizeof(const char *));
> + Â split_props(&props, value, autoprops->pool);
No need to allocate an array here -- split_props() creates and returns one.
> +
> + Â for (i = 0; i < props->nelts; i++)
> Â Â {
> Â Â Â int len;
> + Â Â Â char *new_token;
prop_name, or similar, would be a better name than "new_token"
> Â Â Â const char *this_value;
> - Â Â Â char *equal_sign = strchr(property, '=');
> + Â Â Â const char *token = APR_ARRAY_IDX(props, i, const char *);
> + Â Â Â char *equal_sign = strchr(token, '=');
>
> Â Â Â if (equal_sign)
> Â Â Â Â {
> Â Â Â Â Â *equal_sign = '\0';
> Â Â Â Â Â equal_sign++;
> Â Â Â Â Â trim_string(&equal_sign);
> + Â Â Â Â Â this_value = apr_palloc(autoprops->pool, strlen(equal_sign)+1);
> Â Â Â Â Â this_value = equal_sign;
what is that allocation for? it gets thrown out by the following line anyways
> Â Â Â Â }
> Â Â Â else
> Â Â Â Â {
> Â Â Â Â Â this_value = "";
> Â Â Â Â }
> - Â Â Â trim_string(&property);
> - Â Â Â len = strlen(property);
> + Â Â Â new_token = apr_pstrdup(autoprops->pool, token);
no need to dup this, it was already allocated in autoprops->pool.
> + Â Â Â trim_string(&new_token);
> + Â Â Â len = strlen(new_token);
> +
> Â Â Â if (len > 0)
> Â Â Â Â {
> Â Â Â Â Â svn_string_t *propval = svn_string_create(this_value,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â autoprops->pool);
No need to copy the contents again. Instead:
svn_string_t *propval = apr_palloc(autoprops->pool, sizeof(*propval));
propval->data = this_value;
propval->len = strlen(this_value);
>
> - Â Â Â Â Â apr_hash_set(autoprops->properties, property, len, propval);
> - Â Â Â Â Â if (strcmp(property, SVN_PROP_MIME_TYPE) == 0)
> + Â Â Â Â Â apr_hash_set(autoprops->properties, new_token, len, propval);
> + Â Â Â Â Â if (strcmp(new_token, SVN_PROP_MIME_TYPE) == 0)
> Â Â Â Â Â Â autoprops->mimetype = this_value;
> - Â Â Â Â Â else if (strcmp(property, SVN_PROP_EXECUTABLE) == 0)
> + Â Â Â Â Â else if (strcmp(new_token, SVN_PROP_EXECUTABLE) == 0)
> Â Â Â Â Â Â autoprops->have_executable = TRUE;
> Â Â Â Â }
> - Â Â Â property = apr_strtok(NULL, ";", &last_token);
> Â Â }
> Â return TRUE;
> Â }
>
> ------------------------------------------------------
> http://subversion.tigris.org/ds/viewMessage.do?dsForumId=495&dsMessageId=1411351
>
------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=1415500
Received on 2009-03-25 14:35:07 CET