From 0b5e9e23255689b09a6e76e9565e7c2e3732b155 Mon Sep 17 00:00:00 2001 From: Alik Aslanyan Date: Sat, 19 May 2018 14:42:20 +0400 Subject: [PATCH] Release version Beta 2.5.3 --- CMakeLists.txt | 2 +- src/helper/fast_unordered_string_map.h | 55 ++++++++++++++++++++++++++ src/main.cpp | 2 +- src/module.cpp | 2 +- src/module.h | 26 +++++------- 5 files changed, 67 insertions(+), 20 deletions(-) create mode 100644 src/helper/fast_unordered_string_map.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 30331d4..594e367 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ include_directories(${API_INCLUDE_PATH_LIST}) # tests add_library(${PROJECT_NAME}_static STATIC ${SOURCE_FILES}) -set_target_properties(${PROJECT_NAME}_static PROPERTIES COMPILE_FLAGS "-m32 -O0" LINK_FLAGS "-m32 -O0") +set_target_properties(${PROJECT_NAME}_static PROPERTIES COMPILE_FLAGS "-m32 -pipe -O0" LINK_FLAGS "-m32 -pipe -O0") add_subdirectory(test) # main diff --git a/src/helper/fast_unordered_string_map.h b/src/helper/fast_unordered_string_map.h new file mode 100644 index 0000000..1defb11 --- /dev/null +++ b/src/helper/fast_unordered_string_map.h @@ -0,0 +1,55 @@ +// +// Created by alik on 5/18/18. +// +#pragma once +#ifndef UNPRECACHER_FAST_UNORDERED_STRING_MAP +#define UNPRECACHER_FAST_UNORDERED_STRING_MAP + +#include +#include +#include +#include +#include + +namespace up { + + namespace detail { + struct universal_string_hash { + inline std::size_t operator()(const std::string &v) const { + return std::hash()(v); + } + + inline std::size_t operator()(const std::string_view &v) const { + return std::hash()(v); + } + }; + + struct universal_equal_to { + template + inline bool operator()(const T &v1, const U &v2) const { + return v1 == v2; + } + }; + + using namespace boost::multi_index; + template + using unordered_string_map = multi_index_container< + std::pair, + indexed_by< + hashed_unique< + member< + std::pair, + std::string, + &std::pair::first + >, + universal_string_hash, + universal_equal_to + > + > + >; + } + + template + using fast_unordered_string_map = detail::unordered_string_map; +} +#endif //UNPRECACHER_FAST_UNORDERED_STRING_MAP diff --git a/src/main.cpp b/src/main.cpp index f6be9ba..94154bc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -64,7 +64,7 @@ static META_FUNCTIONS gMetaFunctionTable = { plugin_info_t Plugin_info = { META_INTERFACE_VERSION, "Ultimate Unprecacher", - "Beta 2.5.2", + "Beta 2.5.3", "2016/05/18", "Alik Aslanyan ", "https://github.com/in-line/metamod_unprecacher", diff --git a/src/module.cpp b/src/module.cpp index 6dd73b6..0b8af84 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -188,7 +188,7 @@ bool Module::readLine(std::string line) // Insert our job result logger_->debug(FNAME + " Insert to mapType " + extensionPrefixes[currentMapType]); - maps_[currentMapType][path] = options; + maps_[currentMapType].insert({path, options}); return true; } diff --git a/src/module.h b/src/module.h index a65bfe4..9851907 100644 --- a/src/module.h +++ b/src/module.h @@ -36,22 +36,19 @@ #include #include +#include #include "unprecacheoptions.h" #include "logger.h" #include "config.h" #include "helper/shared.h" - -#include -#include - -#include +#include "helper/fast_unordered_string_map.h" class Module { private: - typedef std::unordered_map UnprecacheMap; + typedef up::fast_unordered_string_map UnprecacheMap; enum MAP { MAP_START = 0, @@ -61,13 +58,12 @@ class Module MAP_SIZE = 3, }; - inline HOT bool checkPathInMap(const std::string &path, MAP mapType) + inline HOT bool checkPathInMap(const std::string_view &path, MAP mapType) noexcept { - const UnprecacheMap::const_iterator &result = maps_[mapType].find(path); - if(result != maps_[mapType].end()) + if(const auto &result = maps_[mapType].find(path); result != maps_[mapType].end()) { #ifdef _DEBUG - logger_->debug(FNAME + " Match. " + path + " -> " + result->first); + logger_->debug(FNAME + " Match. " + std::string(path) + " -> " + result->first); #endif lastHitPoint_ = &result->second; return true; @@ -92,13 +88,9 @@ class Module const Module& operator =(const Module&) = delete; const Module&& operator =(const Module&&) = delete; - inline HOT bool checkSprite(const std::string &path) { return checkPathInMap(path, MAP_SPRITES); } - inline HOT bool checkModel(const std::string &path) { return checkPathInMap(path, MAP_MODELS); } - inline HOT bool checkSound(const std::string &path){ return checkPathInMap(path, MAP_SOUNDS); } - - inline HOT bool checkSprite(const char* path) { return this->checkSprite(std::string(path)); } - inline HOT bool checkModel(const char* path) { return this->checkModel(std::string(path)); } - inline HOT bool checkSound(const char* path) { return this->checkSound(std::string(path)); } + inline HOT bool checkSprite(const std::string_view &path) { return checkPathInMap(path, MAP_SPRITES); } + inline HOT bool checkModel(const std::string_view &path) { return checkPathInMap(path, MAP_MODELS); } + inline HOT bool checkSound(const std::string_view &path){ return checkPathInMap(path, MAP_SOUNDS); } bool readLine(std::string line); void loadLists(const std::string &path);