Re: [xml] Length xmlTextReaderConst... contents?

On Fri, Apr 11, 2008 at 01:10:01PM +0300, Andrew W. Nosenko wrote:
On Fri, Apr 11, 2008 at 8:58 AM, Ralf Junker <ralfjunker gmx de> wrote:
 I need the length to pass it to other functions which do not work on #0-terminated, but 
length-terminated string functions.

  actually no, the parser computed the lenght at some point for example
when interning the string.
  Have you actually tried to do a fine grained analysis, i really doubt
the strlen is taking any noticeable time compared to any useful processing
on top... beware of unchecked performance opinion :-)

Hmm...  What about following idea:

You may try to cache length of strings.
Const family of functions returns pointer to the "interned" string
from the internal Reader dictionary.  It relates to node and attribute

You may prefill it with strings need for- or expected by you using
xmlTextReaderConstString().  In the same time you can calculate
strlen() and fill both (pointer to the interned string and its length)
into e.g. array.

After that you can both save time by eliminating strcmp() and using
direct pointer comparison, and avoid strlen() calls using lookup
inside this prefilled array.

If lookup fails (unknown node or attribute), then you may fallback to
the "usual" strlen() or just ignore unknown element depending of logic
of your application.

  Hum, most compilers optimize strlen() very well, your solution may actually
be more expensive than the speudo call as soon as your array includes more
than a dozen entry which sounds like a very short vocabulary.
  But yes this should return the interned strings,


Red Hat Virtualization group
Daniel Veillard      | virtualization library
veillard redhat com  | libxml GNOME XML XSLT toolkit | Rpmfind RPM search engine

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]