dbertoni 00/12/07 08:39:28
Modified: c/src/PlatformSupport XalanDOMStringPool.cpp
XalanDOMStringPool.hpp
Log:
Implemented ability to use non-null-terminated strings.
Revision Changes Path
1.4 +54 -5 xml-xalan/c/src/PlatformSupport/XalanDOMStringPool.cpp
Index: XalanDOMStringPool.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/XalanDOMStringPool.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- XalanDOMStringPool.cpp 2000/12/06 23:40:40 1.3
+++ XalanDOMStringPool.cpp 2000/12/07 16:39:26 1.4
@@ -64,6 +64,48 @@
+bool
+XalanDOMStringPool::StringKey::operator<(const StringKey& theRHS) const
+{
+ // Note that we don't really need lexicographical ordering, so this
+ // is much cheaper.
+ if (m_length < theRHS.m_length)
+ {
+ return true;
+ }
+ else if (m_length > theRHS.m_length)
+ {
+ return false;
+ }
+ else
+ {
+ unsigned int i = 0;
+
+ while(i < m_length)
+ {
+ if (m_string[i] < theRHS.m_string[i])
+ {
+ return true;
+ }
+ else if (m_string[i] > theRHS.m_string[i])
+ {
+ return false;
+ }
+ else
+ {
+ ++i;
+ }
+ }
+
+ assert(i == m_length && m_string[i] == 0 && theRHS.m_string[i]
== 0);
+
+ // They're equal, so return false...
+ return false;
+ }
+}
+
+
+
XalanDOMStringPool::XalanDOMStringPool() :
m_strings(),
m_index()
@@ -103,7 +145,7 @@
const XalanDOMString&
XalanDOMStringPool::get(const XalanDOMString& theString)
{
- return get(c_wstr(theString));
+ return get(toCharArray(theString), length(theString));
}
@@ -111,7 +153,7 @@
const XalanDOMString&
XalanDOMStringPool::get(
const XalanDOMChar* theString,
- unsigned int /* theLength */)
+ unsigned int theLength)
{
assert(m_strings.size() == m_index.size());
@@ -121,9 +163,11 @@
}
else
{
+ const unsigned int theActualLength = theLength == -1 ?
length(theString) : theLength;
+
// Find the string...
const IteratorMapType::const_iterator i =
- m_index.find(theString);
+ m_index.find(IteratorMapType::key_type(theString,
theActualLength));
if (i != m_index.end())
{
@@ -137,11 +181,16 @@
m_strings.insert(m_strings.end(),
XalanDOMString());
XalanDOMString& theNewString = *theIterator;
+
+ assign(theNewString, theString, theActualLength);
- theNewString = theString;
+ assert(theActualLength == length(theNewString));
// Add an index entry...
-
m_index.insert(IteratorMapType::value_type(c_wstr(theNewString), theIterator));
+ m_index.insert(
+ IteratorMapType::value_type(
+
IteratorMapType::key_type(toCharArray(theNewString), theActualLength),
+ theIterator));
assert(m_strings.size() == m_index.size());
1.4 +35 -8 xml-xalan/c/src/PlatformSupport/XalanDOMStringPool.hpp
Index: XalanDOMStringPool.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/XalanDOMStringPool.hpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- XalanDOMStringPool.hpp 2000/12/06 23:40:40 1.3
+++ XalanDOMStringPool.hpp 2000/12/07 16:39:27 1.4
@@ -70,7 +70,6 @@
#include <PlatformSupport/DOMStringHelper.hpp>
-#include <PlatformSupport/STLHelper.hpp>
@@ -78,20 +77,48 @@
{
public:
+ class StringKey
+ {
+ public:
+
+ explicit
+ StringKey();
+
+ StringKey(
+ const XalanDOMChar* theString,
+ unsigned int theLength) :
+ m_string(theString),
+ m_length(theLength)
+ {
+ }
+
+ ~StringKey()
+ {
+ }
+
+ bool
+ operator<(const StringKey& theRHS) const;
+
+ private:
+
+ const XalanDOMChar* m_string;
+
+ unsigned int m_length;
+ };
+
#if defined(XALAN_NO_NAMESPACES)
- typedef deque<XalanDOMString>
XalanDOMStringCollectionType;
+ typedef deque<XalanDOMString>
XalanDOMStringCollectionType;
typedef map<
- const XalanDOMChar*,
+ StringKey,
XalanDOMStringCollectionType::const_iterator,
- less_null_terminated_arrays<const XalanDOMChar>
> IteratorMapType;
+ less<StringKey> >
IteratorMapType;
#else
- typedef std::deque<XalanDOMString>
XalanDOMStringCollectionType;
+ typedef std::deque<XalanDOMString>
XalanDOMStringCollectionType;
typedef std::map<
- const XalanDOMChar*,
- XalanDOMStringCollectionType::const_iterator,
- less_null_terminated_arrays<const XalanDOMChar>
> IteratorMapType;
+ StringKey,
+ XalanDOMStringCollectionType::const_iterator>
IteratorMapType;
#endif
typedef XalanDOMStringCollectionType::size_type size_type;