[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: svn commit: r14445 - in trunk/subversion: tests/libsvn_subr

From: Philip Martin <philip_at_codematters.co.uk>
Date: 2005-04-25 23:46:43 CEST

kfogel@collab.net writes:

> lundblad@tigris.org writes:
>> --- trunk/subversion/libsvn_subr/path.c (original)
>> +++ trunk/subversion/libsvn_subr/path.c Mon Apr 25 15:14:21 2005
>> @@ -711,40 +711,35 @@
>> skip_uri_scheme (const char *path)
>> {
>> apr_size_t j;
>> - apr_size_t len = strlen (path);
>>
>> - /* ### Taking strlen() initially is inefficient. It's a holdover
>> - from svn_stringbuf_t days. */
>> + assert (path);
>>
>> - /* Make sure we have enough characters to even compare. */
>> - if (len < 4)
>> + /* <scheme> has length > 0 and doesn't contain ':' or '/'.
>> + (i.e. the first char is not ':' or '/')
>> + path[1] and path[2] are tested to assert the precondition
>> + of the following loop. */
>> + if (path[0] == '\0' || path[0] == ':' || path[0] == '/'
>> + || path[1] == '\0' || path[2] == '\0')
>> return NULL;
>>
>> - /* Look for the sequence '://' */
>> - for (j = 0; j < len - 3; j++)
>> + for (j = 1; path[j + 2] != '\0'; ++j)
>> {
>
> Still waiting for Greg Hudson to mutter something about cycle
> counting... but I confess I enjoyed this code :-).

The problem with code like that (apart from it being difficult to
understand) is that other people always think they can do it better :)

  for(j = 0; path[j]; ++j)
    if (path[j] == ':' || path[j] == '/')
       break;

  if (j > 0 && path[j] == ':' && path[j+1] == '/' && path[j+2] == '/')
    return path + j + 3;

  return NULL;

-- 
Philip Martin
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Mon Apr 25 23:48:36 2005

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.