git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Kyle J. McKay" <mackyle@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, "David Aguilar" <davvid@gmail.com>,
	"Petr Baudis" <pasky@ucw.cz>,
	"Richard Hartmann" <richih.mailinglist@gmail.com>,
	"Jeff King" <peff@peff.net>,
	"Daniel Knittl-Frank" <knittl89@googlemail.com>,
	"Jan Krüger" <jk@jk.gs>, "Alejandro Mery" <amery@geeks.cl>,
	"Aaron Schrab" <aaron@schrab.com>,
	"Eric Sunshine" <sunshine@sunshineco.com>
Subject: Re: [PATCH v6 2/4] config: improve support for http.<url>.* settings
Date: Fri, 19 Jul 2013 16:37:54 -0700	[thread overview]
Message-ID: <2544648C-9660-48F0-888A-E78E31477A89@gmail.com> (raw)
In-Reply-To: <7vehauuxqo.fsf@alter.siamese.dyndns.org>

On Jul 19, 2013, at 12:59, Junio C Hamano wrote:
> "Kyle J. McKay" <mackyle@gmail.com> writes:
>
>> +#define URL_ALPHA  
>> "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
>> +#define URL_DIGIT "0123456789"
>> +#define URL_HEXDIGIT URL_DIGIT "ABCDEFabcdef"
>> +#define URL_ALPHADIGIT URL_ALPHA URL_DIGIT
>> +#define URL_SCHEME_CHARS URL_ALPHADIGIT "+.-"
>> +#define URL_HOST_CHARS URL_ALPHADIGIT ".-[:]" /* IPv6 literals  
>> need [:] */
>> +#define URL_UNSAFE_CHARS " <>\"%{}|\\^`" /* plus 0x00-0x1F, 
>> 0x7F-0xFF */
>> +#define URL_GEN_RESERVED ":/?#[]@"
>> +#define URL_SUB_RESERVED "!$&'()*+,;="
>> +#define URL_RESERVED URL_GEN_RESERVED URL_SUB_RESERVED /* only  
>> allowed delims */
>> + ...
>> +	while (from_len) {
>> +		int ch = *from++;
>> +		int was_esc = 0;
>> +
>> +		from_len--;
>> +		if (ch == '%') {
>> +			if (from_len < 2 ||
>> +			    !strchr(URL_HEXDIGIT, from[0]) ||
>> +			    !strchr(URL_HEXDIGIT, from[1]))
>
> I actually do like the readability of the approach in this patch,
> but these repeated strchrs() in a loop may want to be optimized,
> using a trick similar to what is used in ctype.c::sane_ctype[].
>
> A small build-time-only program or script gen-http-ctype.perl that
> defines and uses these URL_* cpp macros and generates a C source
> file http-ctype-gen.c that can be #included from http.c, with
> something like this in the Makefile:
>
> 	http-ctype-gen.c: gen-http-ctype.perl
> 		rm -f $@ $@+
>                $(PERL_PATH) gen-http-ctype.perl >$@+
>                mv $@+ $@
> 	http.o: http.c http-ctype-gen.c
>
> would give us both readability and efficiency, perhaps?

Hmmm.  That's a very fast technique.  However something like:

#define IS_HEX_DIGIT(c) \
   (('0'<=(c)&&(c)<='9')||('a'<=(c)&&(c)<='f')||('A'<=(c)&&(c)<='F'))

I would think would be suitably fast without needing any added build  
files.

However, looks like there is a ctype.h isxdigit() function and it  
looks like there's a version of that in git-compat-util.h as well as a  
convenient hexval_table to use for the conversion, so I will alter the  
code to use those instead which will also do away with the  
hex_digit_value() function.

If you mean for all the strchr etc. calls, multiple tables would be  
required since URL_SCHEME_CHARS and URL_HOST_CHARS partially overlap,  
but it could be done.  Is the speed of strchr that much of a concern?   
The code will only be invoked for http.<url>.* option settings in any  
case and I expect the user would have to set an awfully large number  
of those to even begin to notice.

  reply	other threads:[~2013-07-19 23:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-19 12:48 [PATCH v6 0/4] config: add support for http.<url>.* settings Kyle J. McKay
2013-07-19 12:48 ` [PATCH v6 1/4] " Kyle J. McKay
2013-07-19 20:08   ` Junio C Hamano
2013-07-19 23:40     ` Kyle J. McKay
2013-07-19 12:48 ` [PATCH v6 2/4] config: improve " Kyle J. McKay
2013-07-19 19:59   ` Junio C Hamano
2013-07-19 23:37     ` Kyle J. McKay [this message]
2013-07-20  0:35       ` Junio C Hamano
2013-07-19 12:48 ` [PATCH v6 3/4] tests: add new test for the url_normalize function Kyle J. McKay
2013-07-19 12:48 ` [PATCH v6 4/4] config: allow http.<url>.* any user matching Kyle J. McKay

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2544648C-9660-48F0-888A-E78E31477A89@gmail.com \
    --to=mackyle@gmail.com \
    --cc=aaron@schrab.com \
    --cc=amery@geeks.cl \
    --cc=davvid@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jk@jk.gs \
    --cc=knittl89@googlemail.com \
    --cc=pasky@ucw.cz \
    --cc=peff@peff.net \
    --cc=richih.mailinglist@gmail.com \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).