From: <ag...@us...> - 2008-10-30 17:22:00
|
Revision: 177 http://zoolib.svn.sourceforge.net/zoolib/?rev=177&view=rev Author: agreen Date: 2008-10-30 17:21:56 +0000 (Thu, 30 Oct 2008) Log Message: ----------- Use a local 6 byte buffer when we're asked for fewer than 6 code units. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZStream_ASCIIStrim.cpp Modified: trunk/zoolib/source/cxx/zoolib/ZStream_ASCIIStrim.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZStream_ASCIIStrim.cpp 2008-10-29 01:52:20 UTC (rev 176) +++ trunk/zoolib/source/cxx/zoolib/ZStream_ASCIIStrim.cpp 2008-10-30 17:21:56 UTC (rev 177) @@ -33,31 +33,57 @@ { UTF8* localDest = reinterpret_cast<UTF8*>(iDest); - while (iCount) + if (iCount < 6) { - // Top up our buffer with UTF8 code points. - size_t countRead; - fStrimR.Read(localDest, iCount, &countRead); - if (countRead == 0) - break; + // When reading UTF8 we must have up to six bytes available. + UTF8 buffer[6]; + while (iCount) + { + size_t countCURead; + size_t countCPRead; + fStrimR.Read(buffer, 6, &countCURead, iCount, &countCPRead); + if (countCURead == 0) + break; - // Scan till we find a non-ASCII code point (if any). - for (UTF8* readFrom = localDest, *destEnd = localDest + countRead; - readFrom < destEnd; ++readFrom) + // Trasncribe only ASCII code units/points. + for (UTF8* readFrom = &buffer[0], *destEnd = &buffer[countCURead]; + readFrom < destEnd; ++readFrom) + { + if (*readFrom & 0x80) + continue; + *localDest++ = *readFrom; + --iCount; + } + } + } + else + { + while (iCount) { - if (*readFrom & 0x80) + // Top up our buffer with UTF8 code points. + size_t countRead; + fStrimR.Read(localDest, iCount, &countRead); + if (countRead == 0) + break; + + // Scan till we find a non-ASCII code point (if any). + for (UTF8* readFrom = localDest, *destEnd = localDest + countRead; + readFrom < destEnd; ++readFrom) { - // We found a problem, so start transcribing only those bytes that are okay. - for (UTF8* writeTo = readFrom; readFrom < destEnd; ++readFrom) + if (*readFrom & 0x80) { - if (!(*readFrom & 0x80)) - *writeTo++ = *readFrom; + // We found a problem, so start transcribing only those bytes that are okay. + for (UTF8* writeTo = readFrom; readFrom < destEnd; ++readFrom) + { + if (!(*readFrom & 0x80)) + *writeTo++ = *readFrom; + } + break; } - break; } + localDest += countRead; + iCount -= countRead; } - localDest += countRead; - iCount -= countRead; } if (oCountRead) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |