aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/function/base.h22
-rw-r--r--src/support/dom/document_cache.cc27
-rw-r--r--src/support/dom/document_cache.h10
3 files changed, 13 insertions, 46 deletions
diff --git a/src/function/base.h b/src/function/base.h
index c5346c7..fe9f6ff 100644
--- a/src/function/base.h
+++ b/src/function/base.h
@@ -28,33 +28,23 @@ class FunctionBase : public xalan::Function {
) const {
const FilesystemContext fsContext(locator);
- const boost::filesystem::path argumentPath(
- fsContext.resolve(argument->str())
- );
-
- DomDocumentCache::optional_item optionalCachedDocument(
- this->document_cache_->get(argumentPath.string())
- );
-
- if ( !optionalCachedDocument.first ) {
- optionalCachedDocument = this->document_cache_->create(
- argumentPath.string(),
+ xalan::XalanDocument* const domDocument(
+ this->document_cache_->create(
static_cast<Implementation*>(
const_cast<FunctionBase*>(this)
)->constructDocument(
fsContext,
- argumentPath
+ fsContext.resolve(argument->str())
)
- );
- }
+ )
+ );
xalan::XPathExecutionContext::BorrowReturnMutableNodeRefList nodeList(
executionContext
);
nodeList->addNodes(
- *optionalCachedDocument.second->getDocumentElement()
- ->getChildNodes()
+ *domDocument->getDocumentElement()->getChildNodes()
);
return executionContext.getXObjectFactory().createNodeSet(nodeList);
diff --git a/src/support/dom/document_cache.cc b/src/support/dom/document_cache.cc
index 81d90aa..0ad540c 100644
--- a/src/support/dom/document_cache.cc
+++ b/src/support/dom/document_cache.cc
@@ -6,33 +6,14 @@ namespace InputXSLT {
DomDocumentCache::DomDocumentCache():
write_mutex_(),
- map_() { }
+ cache_() { }
-DomDocumentCache::optional_item DomDocumentCache::get(const std::string& key) {
- auto itemIter = this->map_.find(key);
-
- if ( itemIter == this->map_.end() ) {
- return optional_item(false, nullptr);
- } else {
- return optional_item(true, (*itemIter).second->getXalanDocument());
- }
-}
-
-DomDocumentCache::optional_item DomDocumentCache::create(
- const std::string& key,
- xercesc::DOMDocument* document
-) {
+xalan::XalanDocument* DomDocumentCache::create(xercesc::DOMDocument* document) {
std::lock_guard<std::mutex> guard(this->write_mutex_);
- auto result = this->map_.emplace(
- std::make_pair(key, std::unique_ptr<item>(new item(document)))
- );
+ this->cache_.emplace(new item(document));
- if ( result.second ) {
- return optional_item(true, (*(result.first)).second->getXalanDocument());
- } else {
- return optional_item(false, nullptr);
- }
+ return this->cache_.top()->getXalanDocument();
}
}
diff --git a/src/support/dom/document_cache.h b/src/support/dom/document_cache.h
index cbac5c7..1f9a9e3 100644
--- a/src/support/dom/document_cache.h
+++ b/src/support/dom/document_cache.h
@@ -5,9 +5,8 @@
#include <xercesc/dom/DOMDocument.hpp>
-#include <string>
#include <mutex>
-#include <unordered_map>
+#include <stack>
#include <memory>
#include "common.h"
@@ -16,18 +15,15 @@ namespace InputXSLT {
class DomDocumentCache {
public:
- typedef std::pair<bool, xalan::XalanDocument*> optional_item;
-
DomDocumentCache();
- optional_item get(const std::string&);
- optional_item create(const std::string&, xercesc::DOMDocument*);
+ xalan::XalanDocument* create(xercesc::DOMDocument*);
private:
class item;
std::mutex write_mutex_;
- std::unordered_map<std::string, std::unique_ptr<item>> map_;
+ std::stack<std::unique_ptr<item>> cache_;
};