You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by "Peter A. Volchek" <Pe...@ti.com.od.ua> on 2001/06/14 20:24:30 UTC

transcode results

I think that transcode function should also return the number of transcoded
chars (the length of transcode sting)

Motivation:
Let's see DOMString constructor
DOMString::DOMString(const char *srcString)
{
...
        const unsigned int charsNeeded =
            uniConverter->calcRequiredSize(srcString);
...
        fHandle->fLength = charsNeeded;
...
        if (!uniConverter->transcode(srcString, strData, charsNeeded))
        {
            // <TBD> We should throw something here?
        }
    }
};

Actually, when calcRequiredSize(srcString); is called, the transcoding
occurs
See, for example Win32Transcoder

const unsigned int retVal = ::mbstowcs(0, srcText, 0);
In spite of the destination buffer is not passed, the functions do its job.
It transcodes the input source
and returns the number of characters to allocate.
later, when calling transcode, this function is called agen. So we have a
performance leak.

What could be done here?
One of the approaches is to cache the transcoded value, and do not transcode
second time.

Another, that I vote, is to modify the fLength member with the value retuned
by transcode method, like
        fHandle->fLength = charsNeeded;
...
        unsigned int chRet = 0;
        chRet = uniConverter->transcode(srcString, strData, charsNeeded);
        fHandle->fLength = chRet;

P.S.
The matter is, that I use the third-party transcoder, that can only return
the worst-case conversion expansion ratio. So the number of transcoded chars
can differ from expected.



Peter A. Volchek
Software Engineer
Metis International, Inc.
PeterV@ti.com.od.ua



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org