Skip to content

Commit

Permalink
IMSMWU#55 thread safe ast cache (IMSMWU#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
artpaul authored Jun 18, 2019
1 parent 8088706 commit 3d7f9ca
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion clickhouse/types/type_parser.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "type_parser.h"
#include "../base/string_utils.h"

#include <map>
#include <mutex>
#include <unordered_map>

namespace clickhouse {
Expand Down Expand Up @@ -167,8 +169,10 @@ const TypeAst* ParseTypeName(const std::string& type_name) {
// Cache for type_name.
// Usually we won't have too many type names in the cache, so do not try to
// limit cache size.
static std::unordered_map<std::string, TypeAst> ast_cache;
static std::map<std::string, TypeAst> ast_cache;
static std::mutex lock;

std::lock_guard<std::mutex> guard(lock);
auto it = ast_cache.find(type_name);
if (it != ast_cache.end()) {
return &it->second;
Expand Down

0 comments on commit 3d7f9ca

Please sign in to comment.