1 | /* |
---|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
3 | * contributor license agreements. See the NOTICE file distributed with |
---|
4 | * this work for additional information regarding copyright ownership. |
---|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
6 | * (the "License"); you may not use this file except in compliance with |
---|
7 | * the License. You may obtain a copy of the License at |
---|
8 | * |
---|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
10 | * |
---|
11 | * Unless required by applicable law or agreed to in writing, software |
---|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
14 | * See the License for the specific language governing permissions and |
---|
15 | * limitations under the License. |
---|
16 | */ |
---|
17 | |
---|
18 | /* |
---|
19 | * $Id: DOMStringPool.cpp 678766 2008-07-22 14:00:16Z borisk $ |
---|
20 | */ |
---|
21 | |
---|
22 | #include <icxercesc/util/XMLString.hpp> |
---|
23 | #include <icxercesc/util/PlatformUtils.hpp> |
---|
24 | |
---|
25 | #include "DOMStringPool.hpp" |
---|
26 | #include "DOMDocumentImpl.hpp" |
---|
27 | |
---|
28 | XERCES_CPP_NAMESPACE_BEGIN |
---|
29 | |
---|
30 | DOMBuffer:: |
---|
31 | DOMBuffer(DOMDocumentImpl *doc, XMLSize_t capacity) : |
---|
32 | fBuffer(0) |
---|
33 | , fIndex(0) |
---|
34 | , fCapacity(capacity) |
---|
35 | , fDoc(doc) |
---|
36 | { |
---|
37 | // Buffer is one larger than capacity, to allow for zero term |
---|
38 | fBuffer = (XMLCh*) doc->allocate((fCapacity+1)*sizeof(XMLCh)); |
---|
39 | |
---|
40 | // Keep it null terminated |
---|
41 | fBuffer[0] = XMLCh(0); |
---|
42 | } |
---|
43 | |
---|
44 | // --------------------------------------------------------------------------- |
---|
45 | // DOMBuffer: Private helper methods |
---|
46 | // --------------------------------------------------------------------------- |
---|
47 | void DOMBuffer::expandCapacity(const XMLSize_t extraNeeded) |
---|
48 | { |
---|
49 | //not enough room. Calc new capacity and allocate new buffer |
---|
50 | const XMLSize_t newCap = (XMLSize_t)((fIndex + extraNeeded) * 1.25); |
---|
51 | XMLCh* newBuf = (XMLCh*) fDoc->allocate((newCap+1)*sizeof(XMLCh)); |
---|
52 | |
---|
53 | // Copy over the old stuff |
---|
54 | memcpy(newBuf, fBuffer, fCapacity * sizeof(XMLCh)); |
---|
55 | |
---|
56 | // revisit: Leave the old buffer in document heap, yes, this is a leak, but live with it! |
---|
57 | // store new stuff |
---|
58 | fBuffer = newBuf; |
---|
59 | fCapacity = newCap; |
---|
60 | } |
---|
61 | |
---|
62 | XERCES_CPP_NAMESPACE_END |
---|