~ubuntu-branches/ubuntu/precise/xerces-c/precise-security

« back to all changes in this revision

Viewing changes to src/xercesc/util/SynchronizedStringPool.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jay Berkenbilt
  • Date: 2010-02-06 16:46:23 UTC
  • mfrom: (2.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20100206164623-xbntkcs6ks20nboa
Tags: 3.1.0-1
* New upstream release
* Updated standards version to 3.8.4.  No changes required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
6
 * (the "License"); you may not use this file except in compliance with
7
7
 * the License.  You may obtain a copy of the License at
8
 
 * 
 
8
 *
9
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 
 * 
 
10
 *
11
11
 * Unless required by applicable law or agreed to in writing, software
12
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
16
 */
17
17
 
18
18
/*
19
 
 * $Id: SynchronizedStringPool.cpp 471747 2006-11-06 14:31:56Z amassari $
 
19
 * $Id: SynchronizedStringPool.cpp 903137 2010-01-26 09:26:28Z borisk $
20
20
 */
21
21
 
22
22
 
56
56
        return id;
57
57
    // might have to add it to our own table.
58
58
    // synchronize this bit
59
 
    {
60
 
        XMLMutexLock lockInit(&fMutex);
61
 
        id = XMLStringPool::addOrFind(newString);
62
 
        return id+fConstPool->getStringCount();
63
 
    }
 
59
    unsigned int constCount = fConstPool->getStringCount();
 
60
    XMLMutexLock lockInit(&fMutex);
 
61
    id = XMLStringPool::addOrFind(newString);
 
62
    return id+constCount;
64
63
}
65
64
 
66
65
bool XMLSynchronizedStringPool::exists(const XMLCh* const newString) const
67
66
{
68
67
    if(fConstPool->exists(newString))
69
68
        return true;
 
69
 
 
70
    XMLMutexLock lockInit(&const_cast<XMLSynchronizedStringPool*>(this)->fMutex);
70
71
    return XMLStringPool::exists(newString);
71
72
}
72
73
 
73
74
bool XMLSynchronizedStringPool::exists(const unsigned int id) const
74
75
{
75
 
    if (!id || (id >= fCurId+fConstPool->getStringCount()))
 
76
    if (!id)
76
77
        return false;
77
78
 
78
 
    return true;
 
79
    // First see if this id belongs to the const pool.
 
80
    //
 
81
    unsigned int constCount = fConstPool->getStringCount();
 
82
 
 
83
    if (id <= constCount)
 
84
      return true;
 
85
 
 
86
    // The rest needs to be synchronized.
 
87
    //
 
88
    XMLMutexLock lockInit(&const_cast<XMLSynchronizedStringPool*>(this)->fMutex);
 
89
    return id < fCurId + constCount;
79
90
}
80
91
 
81
92
void XMLSynchronizedStringPool::flushAll()
90
101
    unsigned int retVal = fConstPool->getId(toFind);
91
102
    if(retVal)
92
103
        return retVal;
 
104
 
93
105
    // make sure we return a truly unique id
94
 
    return XMLStringPool::getId(toFind)+fConstPool->getStringCount();
 
106
    unsigned int constCount = fConstPool->getStringCount();
 
107
    XMLMutexLock lockInit(&const_cast<XMLSynchronizedStringPool*>(this)->fMutex);
 
108
    return XMLStringPool::getId(toFind)+constCount;
95
109
}
96
110
 
97
111
 
99
113
{
100
114
    if (id <= fConstPool->getStringCount())
101
115
        return fConstPool->getValueForId(id);
102
 
    return XMLStringPool::getValueForId(id-fConstPool->getStringCount());
 
116
 
 
117
    unsigned int constCount = fConstPool->getStringCount();
 
118
    XMLMutexLock lockInit(&const_cast<XMLSynchronizedStringPool*>(this)->fMutex);
 
119
    return XMLStringPool::getValueForId(id-constCount);
103
120
}
104
121
 
105
122
unsigned int XMLSynchronizedStringPool::getStringCount() const
106
123
{
107
 
    return fCurId+fConstPool->getStringCount()-1;
 
124
    unsigned int constCount = fConstPool->getStringCount();
 
125
    XMLMutexLock lockInit(&const_cast<XMLSynchronizedStringPool*>(this)->fMutex);
 
126
    return fCurId+constCount-1;
108
127
}
109
128
 
110
129
XERCES_CPP_NAMESPACE_END