Browse Source

Faster GeoIP lookups.

QCache results in speed decrease.
See https://github.com/qbittorrent/qBittorrent/pull/3488#issuecomment-124731983
adaptive-webui-19844
sledgehammer999 9 years ago
parent
commit
ad7ad8f596
  1. 12
      src/core/net/geoipmanager.cpp
  2. 1
      src/core/net/geoipmanager.h

12
src/core/net/geoipmanager.cpp

@ -57,7 +57,6 @@ GeoIPManager *GeoIPManager::m_instance = 0;
GeoIPManager::GeoIPManager() GeoIPManager::GeoIPManager()
: m_enabled(false) : m_enabled(false)
, m_geoIPDatabase(0) , m_geoIPDatabase(0)
, m_cache(CACHE_SIZE)
{ {
configure(); configure();
connect(Preferences::instance(), SIGNAL(changed()), SLOT(configure())); connect(Preferences::instance(), SIGNAL(changed()), SLOT(configure()));
@ -126,15 +125,8 @@ void GeoIPManager::downloadDatabaseFile()
QString GeoIPManager::lookup(const QHostAddress &hostAddr) const QString GeoIPManager::lookup(const QHostAddress &hostAddr) const
{ {
if (m_enabled && m_geoIPDatabase) { if (m_enabled && m_geoIPDatabase)
QString *country = m_cache.object(hostAddr); return m_geoIPDatabase->lookup(hostAddr);
if (country)
return *country;
QString code = m_geoIPDatabase->lookup(hostAddr);
m_cache.insert(hostAddr, new QString(code));
return code;
}
return QString(); return QString();
} }

1
src/core/net/geoipmanager.h

@ -68,7 +68,6 @@ namespace Net
bool m_enabled; bool m_enabled;
GeoIPDatabase *m_geoIPDatabase; GeoIPDatabase *m_geoIPDatabase;
mutable QCache<QHostAddress, QString> m_cache;
static GeoIPManager *m_instance; static GeoIPManager *m_instance;
}; };

Loading…
Cancel
Save