Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2005-09-28 10:28:20


> Is there any reason why it was done this way? For threading issues?

LOL, it is done that way because

a) that was the first way it occurred to me to do it
b) it worked
c) it didn't occur to me when I wrote it that there might be a performance
issue

Of course, now that you mention it ...

My first inclination would be to use

const unsigned char lookup_table[] = { ...

Though I'm not sure that every compiler will exploit the const-ness to avoid
re-initalizing lookup_table[] every time.

Thanks for a very astute observation.

Robert Ramey

Sean Huang wrote:
> I ran across the implementation of XML_name. It is a functor used to
> validate each single character in an XML name. The initialization of a
> stack-based look-up table everytime the functor is called puzzles me
> (see excerpt below).
>
> void operator()(CharType t) const{
> unsigned char lookup_table[] = {
> 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
> 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
> 0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0, // -.
> 1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0, // 0-9
> 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // A-
> 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1, // -Z _
> 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // a-
> 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, // -z
> 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
> 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
> };
> if((unsigned)t > 127)
> return;
> if(0 == lookup_table[(unsigned)t])
> boost::throw_exception(
> xml_archive_exception(
> xml_archive_exception::xml_archive_tag_name_error
> )
> );
> }
>
> Is there any reason why it was done this way? For threading issues?
>
> Thanks,
>
> Sean
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk