zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #06901
[Merge] lp:~zorba-coders/zorba/structural-any-uri-lazy into lp:zorba
Ghislain Fourny has proposed merging lp:~zorba-coders/zorba/structural-any-uri-lazy into lp:zorba.
Requested reviews:
Matthias Brantner (matthias-brantner)
For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/structural-any-uri-lazy/+merge/99707
Made URI computation lazy in StructuralAnyUri.
--
https://code.launchpad.net/~zorba-coders/zorba/structural-any-uri-lazy/+merge/99707
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/store/naive/atomic_items.cpp'
--- src/store/naive/atomic_items.cpp 2012-03-27 00:56:11 +0000
+++ src/store/naive/atomic_items.cpp 2012-03-28 12:10:27 +0000
@@ -1079,7 +1079,6 @@
********************************************************************************/
StructuralAnyUriItem::StructuralAnyUriItem(
- zstring& encoded,
ulong collectionId,
ulong treeId,
store::StoreConsts::NodeKind nodeKind,
@@ -1088,20 +1087,21 @@
theCollectionId(collectionId),
theTreeId(treeId),
theNodeKind(nodeKind),
- theOrdPath(ordPath)
-{
- theValue.take(encoded);
-}
-
+ theOrdPath(ordPath),
+ theIsEncoded(false),
+ theEncodedValue("")
+{}
StructuralAnyUriItem::StructuralAnyUriItem(zstring& value)
+ : theIsEncoded(true)
{
- theValue.take(value);
+ theEncodedValue.take(value);
+ std::istringstream input(theEncodedValue.str());
ulong prefixlen = (ulong)strlen("zorba:");
- if (strncmp(theValue.c_str(), "zorba:", prefixlen))
- throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(theValue));
+ if (strncmp(theEncodedValue.c_str(), "zorba:", prefixlen))
+ throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(theEncodedValue));
const char* start;
@@ -1110,19 +1110,19 @@
//
// Decode collection id
//
- start = theValue.c_str() + prefixlen;
+ start = theEncodedValue.c_str() + prefixlen;
char* next = const_cast<char*>(start);
theCollectionId = strtoul(start, &next, 10);
if (errno != 0 || start == next)
- throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(theValue));
+ throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(theEncodedValue));
start = next;
if (*start != '.')
- throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(theValue));
+ throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(theEncodedValue));
++start;
@@ -1132,12 +1132,12 @@
theTreeId = strtoul(start, &next, 10);
if (errno != 0 || start == next)
- throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(theValue));
+ throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(theEncodedValue));
start = next;
if (*start != '.')
- throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(theValue));
+ throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(theEncodedValue));
++start;
@@ -1147,12 +1147,12 @@
if (*start > '0' && *start <='6')
theNodeKind = static_cast<store::StoreConsts::NodeKind>(*start-'0');
else
- throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(theValue));
+ throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(theEncodedValue));
++start;
if (*start != '.')
- throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(theValue));
+ throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(theEncodedValue));
++start;
@@ -1162,6 +1162,97 @@
theOrdPath = OrdPath((unsigned char*)start, (ulong)strlen(start));
}
+void StructuralAnyUriItem::encode() const
+{
+ ZORBA_FATAL(theNodeKind,"Unexpected node kind");
+ std::ostringstream stream;
+ stream << "zorba:"
+ << theCollectionId << "."
+ << theTreeId << "."
+ << static_cast<int>(theNodeKind) << "."
+ << theOrdPath.serialize();
+ zorba::zstring lValue = stream.str();
+ theEncodedValue.take(lValue);
+ theIsEncoded = true;
+}
+
+
+zstring StructuralAnyUriItem::show() const
+{
+ zstring res("xs:anyURI(");
+ res += getString();
+ res += ")";
+ return res;
+}
+
+bool StructuralAnyUriItem::equals(
+ const store::Item* item,
+ long timezone,
+ const XQPCollator* aCollation) const
+{
+ const StructuralAnyUriItem* lOther =
+ dynamic_cast<const StructuralAnyUriItem*>(item);
+ return (lOther &&
+ lOther->theCollectionId == theCollectionId &&
+ lOther->theTreeId == theTreeId &&
+ lOther->theNodeKind == theNodeKind &&
+ lOther->theOrdPath == theOrdPath);
+}
+
+long StructuralAnyUriItem::compare(
+ const Item* other,
+ long timezone,
+ const XQPCollator* aCollation) const
+{
+ const StructuralAnyUriItem* lOther =
+ dynamic_cast<const StructuralAnyUriItem*>(other);
+ assert(lOther);
+ if (theCollectionId < lOther->theCollectionId)
+ {
+ return -1;
+ }
+ if (theCollectionId > lOther->theCollectionId)
+ {
+ return 1;
+ }
+ if (theTreeId < lOther->theTreeId)
+ {
+ return -1;
+ }
+ if (theTreeId > lOther->theTreeId)
+ {
+ return 1;
+ }
+ if (theNodeKind < lOther->theNodeKind)
+ {
+ return -1;
+ }
+ if (theNodeKind > lOther->theNodeKind)
+ {
+ return 1;
+ }
+ if (theOrdPath < lOther->theOrdPath)
+ {
+ return -1;
+ }
+ if (theOrdPath > lOther->theOrdPath)
+ {
+ return 1;
+ }
+ return 0;
+}
+
+zstring StructuralAnyUriItem::getStringValue() const {
+ return getString();
+}
+
+void StructuralAnyUriItem::getStringValue2(zstring& val) const {
+ val = getString();
+}
+
+void StructuralAnyUriItem::appendStringValue(zstring& buf) const {
+ buf += getString();
+}
bool StructuralAnyUriItem::isAncestor(const store::Item_t& aOther) const
{
=== modified file 'src/store/naive/atomic_items.h'
--- src/store/naive/atomic_items.h 2012-03-27 00:56:11 +0000
+++ src/store/naive/atomic_items.h 2012-03-28 12:10:27 +0000
@@ -710,6 +710,12 @@
ulong theTreeId;
store::StoreConsts::NodeKind theNodeKind;
OrdPath theOrdPath;
+
+ // The value is computed lazily when needed.
+ // The field "theValue" of the base class is not used,
+ // because it is not mutable.
+ mutable bool theIsEncoded;
+ mutable zstring theEncodedValue;
protected:
virtual AnyUriTypeCode getAnyUriTypeCode() const
@@ -720,7 +726,6 @@
StructuralAnyUriItem(zstring& value);
StructuralAnyUriItem(
- zstring& value,
ulong collectionId,
ulong treeId,
store::StoreConsts::NodeKind nodeKind,
@@ -728,7 +733,41 @@
StructuralAnyUriItem() {}
+private:
+ // Forces computation of the value.
+ void encode() const;
+
public:
+ bool equals(
+ const store::Item* item,
+ long timezone = 0,
+ const XQPCollator* aCollation = 0) const;
+
+ long compare(
+ const Item* other,
+ long timezone = 0,
+ const XQPCollator* aCollation = 0) const;
+
+ // A structural URI is never empty.
+ bool getEBV() const { return true; }
+
+ zstring getStringValue() const;
+
+ void getStringValue2(zstring& val) const;
+
+ void appendStringValue(zstring& buf) const;
+
+ const zstring& getString() const
+ {
+ if (!theIsEncoded)
+ {
+ encode();
+ }
+ return theEncodedValue;
+ }
+
+ zstring show() const;
+
bool
isAncestor(const store::Item_t&) const;
=== modified file 'src/store/naive/simple_item_factory.cpp'
--- src/store/naive/simple_item_factory.cpp 2012-03-27 00:56:11 +0000
+++ src/store/naive/simple_item_factory.cpp 2012-03-28 12:10:27 +0000
@@ -125,16 +125,7 @@
const OrdPath& ordPath)
{
ZORBA_FATAL(nodeKind,"Unexpected node kind");
- std::ostringstream stream;
- stream << "zorba:"
- << collectionId << "."
- << treeId << "."
- << static_cast<int>(nodeKind) << "."
- << ordPath.serialize();
- zstring uri = stream.str();
-
- theUriPool->insert(uri);
- result = new StructuralAnyUriItem(uri, collectionId, treeId, nodeKind, ordPath);
+ result = new StructuralAnyUriItem(collectionId, treeId, nodeKind, ordPath);
return true;
}
Follow ups
-
[Merge] lp:~zorba-coders/zorba/structural-any-uri-lazy into lp:zorba
From: Zorba Build Bot, 2012-05-05
-
Re: [Merge] lp:~zorba-coders/zorba/structural-any-uri-lazy into lp:zorba
From: Zorba Build Bot, 2012-05-05
-
[Merge] lp:~zorba-coders/zorba/structural-any-uri-lazy into lp:zorba
From: Zorba Build Bot, 2012-05-05
-
[Merge] lp:~zorba-coders/zorba/structural-any-uri-lazy into lp:zorba
From: Zorba Build Bot, 2012-05-05
-
[Merge] lp:~zorba-coders/zorba/structural-any-uri-lazy into lp:zorba
From: Zorba Build Bot, 2012-05-05
-
[Merge] lp:~zorba-coders/zorba/structural-any-uri-lazy into lp:zorba
From: Zorba Build Bot, 2012-05-04
-
[Merge] lp:~zorba-coders/zorba/structural-any-uri-lazy into lp:zorba
From: Ghislain Fourny, 2012-05-04
-
[Merge] lp:~zorba-coders/zorba/structural-any-uri-lazy into lp:zorba
From: Zorba Build Bot, 2012-04-24
-
Re: [Merge] lp:~zorba-coders/zorba/structural-any-uri-lazy into lp:zorba
From: Zorba Build Bot, 2012-04-24
-
[Merge] lp:~zorba-coders/zorba/structural-any-uri-lazy into lp:zorba
From: Ghislain Fourny, 2012-04-24
-
[Merge] lp:~zorba-coders/zorba/structural-any-uri-lazy into lp:zorba
From: Zorba Build Bot, 2012-04-04
-
Re: [Merge] lp:~zorba-coders/zorba/structural-any-uri-lazy into lp:zorba
From: Zorba Build Bot, 2012-04-04
-
[Merge] lp:~zorba-coders/zorba/structural-any-uri-lazy into lp:zorba
From: Zorba Build Bot, 2012-04-04
-
Re: [Merge] lp:~zorba-coders/zorba/structural-any-uri-lazy into lp:zorba
From: Markos Zaharioudakis, 2012-04-04
-
[Merge] lp:~zorba-coders/zorba/structural-any-uri-lazy into lp:zorba
From: Zorba Build Bot, 2012-04-04
-
Re: [Merge] lp:~zorba-coders/zorba/structural-any-uri-lazy into lp:zorba
From: Ghislain Fourny, 2012-04-04
-
[Merge] lp:~zorba-coders/zorba/structural-any-uri-lazy into lp:zorba
From: Ghislain Fourny, 2012-04-04
-
Re: [Merge] lp:~zorba-coders/zorba/structural-any-uri-lazy into lp:zorba
From: Markos Zaharioudakis, 2012-04-02
-
Re: [Merge] lp:~zorba-coders/zorba/structural-any-uri-lazy into lp:zorba
From: Markos Zaharioudakis, 2012-04-02
-
[Merge] lp:~zorba-coders/zorba/structural-any-uri-lazy into lp:zorba
From: Zorba Build Bot, 2012-03-28
-
Re: [Merge] lp:~zorba-coders/zorba/structural-any-uri-lazy into lp:zorba
From: Zorba Build Bot, 2012-03-28
-
[Merge] lp:~zorba-coders/zorba/structural-any-uri-lazy into lp:zorba
From: Zorba Build Bot, 2012-03-28
-
[Merge] lp:~zorba-coders/zorba/structural-any-uri-lazy into lp:zorba
From: Zorba Build Bot, 2012-03-28
-
[Merge] lp:~zorba-coders/zorba/structural-any-uri-lazy into lp:zorba
From: Matthias Brantner, 2012-03-28
-
Re: [Merge] lp:~zorba-coders/zorba/structural-any-uri-lazy into lp:zorba
From: Matthias Brantner, 2012-03-28