Skip to content

Commit

Permalink
Release version Beta 2.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
In-line committed May 19, 2018
1 parent 8498c77 commit 0b5e9e2
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 20 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 55 additions & 0 deletions src/helper/fast_unordered_string_map.h
Original file line number Diff line number Diff line change
@@ -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 <boost/multi_index_container.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/member.hpp>
#include <string>
#include <string_view>

namespace up {

namespace detail {
struct universal_string_hash {
inline std::size_t operator()(const std::string &v) const {
return std::hash<std::string>()(v);
}

inline std::size_t operator()(const std::string_view &v) const {
return std::hash<std::string_view>()(v);
}
};

struct universal_equal_to {
template<typename T, typename U>
inline bool operator()(const T &v1, const U &v2) const {
return v1 == v2;
}
};

using namespace boost::multi_index;
template<typename T>
using unordered_string_map = multi_index_container<
std::pair<std::string, T>,
indexed_by<
hashed_unique<
member<
std::pair<std::string, T>,
std::string,
&std::pair<std::string, T>::first
>,
universal_string_hash,
universal_equal_to
>
>
>;
}

template<typename T>
using fast_unordered_string_map = detail::unordered_string_map<T>;
}
#endif //UNPRECACHER_FAST_UNORDERED_STRING_MAP
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>",
"https://github.com/in-line/metamod_unprecacher",
Expand Down
2 changes: 1 addition & 1 deletion src/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
26 changes: 9 additions & 17 deletions src/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,19 @@

#include <string>
#include <algorithm>
#include <functional>


#include "unprecacheoptions.h"
#include "logger.h"
#include "config.h"
#include "helper/shared.h"

#include <unordered_map>
#include <string>

#include <functional>
#include "helper/fast_unordered_string_map.h"

class Module
{
private:
typedef std::unordered_map<std::string, UnprecacheOptions> UnprecacheMap;
typedef up::fast_unordered_string_map<UnprecacheOptions> UnprecacheMap;
enum MAP
{
MAP_START = 0,
Expand All @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 0b5e9e2

Please sign in to comment.