diff --git a/doc/releases.xml b/doc/releases.xml index 33f8dc21b2fed6c5d7f15eaa89827446936765e2..dd65694ed4936cdf40b4116b2752d08b326126cb 100644 --- a/doc/releases.xml +++ b/doc/releases.xml @@ -11,6 +11,55 @@ <td>Description</td> </tr> + <tr> + <td>2001-12-14</td> + <td>Tinny Ng</td> + <td>Performance: Do not transcode twice in DOMString constructor. + </td> + </tr> + + <tr> + <td>2001-12-14</td> + <td>Tinny Ng</td> + <td>update BUILDINSTRUCTIONS.TXT to be in sync with build instruction in build*.xml. + </td> + </tr> + + <tr> + <td>2001-12-13</td> + <td>PeiYong Zhang</td> + <td>Fix: Invalid Argument to FreeLibrary (Hint: 0x0000000). + </td> + </tr> + + <tr> + <td>2001-12-13</td> + <td>Linda Swan</td> + <td>iSeries (AS/400) documentation update and other iSeries related fixes. + </td> + </tr> + + <tr> + <td>2001-12-13</td> + <td>Khaled Noamanc</td> + <td>[Bug 5410] non-schema <attribute> attributes cause error. + </td> + </tr> + + <tr> + <td>2001-12-12</td> + <td>Tinny Ng</td> + <td>Fix typos in messages. + </td> + </tr> + + <tr> + <td>2001-12-12</td> + <td>PeiYong Zhang</td> + <td>Memory leak: fRedefineList. + </td> + </tr> + <tr> <td>2001-12-12</td> <td>Tinny Ng</td> diff --git a/src/dom/DOMString.cpp b/src/dom/DOMString.cpp index fae8fafa35163305b006c142a1faef16ea859ea2..bdfee996253cc93b388d31f1828d1c0c73de1d75 100644 --- a/src/dom/DOMString.cpp +++ b/src/dom/DOMString.cpp @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.24 2001/12/14 15:16:51 tng + * Performance: Do not transcode twice in DOMString constructor. + * * Revision 1.23 2001/10/22 17:53:05 tng * [Bug 3660] Off-by-one error in DOMString.cpp. And check that memory has been acquired successfully after memory acquistion requests in DOMString. * @@ -527,15 +530,31 @@ DOMString::DOMString(const char *srcString) if (srcLen == 0) return; - const unsigned int charsNeeded = - uniConverter->calcRequiredSize(srcString); - - fHandle = DOMStringHandle::createNewStringHandle(charsNeeded + 1); - fHandle->fLength = charsNeeded; + // The charsNeeded normally is same as srcLen. To enhance performance, + // we start with this estimate, and if overflow, then call calcRequiredSize for actual size + fHandle = DOMStringHandle::createNewStringHandle(srcLen + 1); + fHandle->fLength = srcLen; XMLCh *strData = fHandle->fDSData->fData; - if (!uniConverter->transcode(srcString, strData, charsNeeded)) + + if (!uniConverter->transcode(srcString, strData, srcLen)) { - // <TBD> We should throw something here? + // conversion failed, so try again + if (fHandle) + fHandle->removeRef(); + + fHandle = 0; + + const unsigned int charsNeeded = + uniConverter->calcRequiredSize(srcString); + + fHandle = DOMStringHandle::createNewStringHandle(charsNeeded + 1); + fHandle->fLength = charsNeeded; + XMLCh *strData2 = fHandle->fDSData->fData; + + if (!uniConverter->transcode(srcString, strData2, charsNeeded)) + { + // <TBD> We should throw something here? + } } } }; @@ -1063,12 +1082,20 @@ char *DOMString::transcode() const // Find out how many output chars we need and allocate a buffer big enough // for that plus a null. // - const unsigned int charsNeeded = getDomConverter()->calcRequiredSize(srcP); + // The charsNeeded normally is same as fHandle->fLength. To enhance performance, + // we start with this estimate, and if overflow, then call calcRequiredSize for actual size + const unsigned int charsNeeded = fHandle->fLength; char* retP = new char[charsNeeded + 1]; if (!getDomConverter()->transcode(srcP, retP, charsNeeded)) { - // <TBD> We should throw something here? + delete [] retP; + const unsigned int charsNeeded2 = getDomConverter()->calcRequiredSize(srcP); + retP = new char[charsNeeded2 + 1]; + if (!getDomConverter()->transcode(srcP, retP, charsNeeded2)) + { + // <TBD> We should throw something here? + } } delete [] allocatedBuf; // which will be null if we didn't allocate one.