summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2011-02-12 13:54:17 (GMT)
committerRemko Tronçon <git@el-tramo.be>2011-02-12 14:27:05 (GMT)
commitb734b6a5986703b6b10ea548c93af11f9df771bf (patch)
treeb7cb4230b556fe4104e5901941e055a2beae51cd /Swiften/JID
parentb75cf274d8c3cf255fd1d8932a9f6a6cfa8cb9b4 (diff)
downloadswift-b734b6a5986703b6b10ea548c93af11f9df771bf.zip
swift-b734b6a5986703b6b10ea548c93af11f9df771bf.tar.bz2
Cache stringprep results for JIDs.
Diffstat (limited to 'Swiften/JID')
-rw-r--r--Swiften/JID/JID.cpp39
1 files changed, 38 insertions, 1 deletions
diff --git a/Swiften/JID/JID.cpp b/Swiften/JID/JID.cpp
index cf5317e..3ecd881 100644
--- a/Swiften/JID/JID.cpp
+++ b/Swiften/JID/JID.cpp
@@ -4,13 +4,28 @@
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#include <stringprep.h>
+#define SWIFTEN_CACHE_JID_PREP
+
#include <vector>
#include <iostream>
+#include <Swiften/Base/String.h>
+#ifdef SWIFTEN_CACHE_JID_PREP
+#include <boost/unordered_map.hpp>
+#endif
+#include <stringprep.h>
+
#include "Swiften/JID/JID.h"
#include "Swiften/IDN/StringPrep.h"
+#ifdef SWIFTEN_CACHE_JID_PREP
+typedef boost::unordered_map<std::string, Swift::String> PrepCache;
+
+static PrepCache nodePrepCache;
+static PrepCache domainPrepCache;
+static PrepCache resourcePrepCache;
+#endif
+
namespace Swift {
JID::JID(const char* jid) {
@@ -56,9 +71,31 @@ void JID::initializeFromString(const String& jid) {
void JID::nameprepAndSetComponents(const String& node, const String& domain, const String& resource) {
+#ifndef SWIFTEN_CACHE_JID_PREP
node_ = StringPrep::getPrepared(node, StringPrep::NamePrep);
domain_ = StringPrep::getPrepared(domain, StringPrep::XMPPNodePrep);
resource_ = StringPrep::getPrepared(resource, StringPrep::XMPPResourcePrep);
+#else
+ std::pair<PrepCache::iterator, bool> r;
+
+ r = nodePrepCache.insert(std::make_pair(node.getUTF8String(), String()));
+ if (r.second) {
+ r.first->second = StringPrep::getPrepared(node, StringPrep::NamePrep);
+ }
+ node_ = r.first->second;
+
+ r = domainPrepCache.insert(std::make_pair(domain.getUTF8String(), String()));
+ if (r.second) {
+ r.first->second = StringPrep::getPrepared(domain, StringPrep::XMPPNodePrep);
+ }
+ domain_ = r.first->second;
+
+ r = resourcePrepCache.insert(std::make_pair(resource.getUTF8String(), String()));
+ if (r.second) {
+ r.first->second = StringPrep::getPrepared(resource, StringPrep::XMPPResourcePrep);
+ }
+ resource_ = r.first->second;
+#endif
}
String JID::toString() const {