Skip to content

Commit

Permalink
Remove legacy base/hash_tables.h in favor of C++11
Browse files Browse the repository at this point in the history
With this CL all the uses of base/hash_tables.h are replaced with std::unordered_set and std::unordered_map in favor of C++11.

No user-visible behavior change is intended.

BUG=none
TEST=unittest

git-svn-id: https://mozc.googlecode.com/svn/trunk@521 a6090854-d499-a067-5803-1114d4e51264
  • Loading branch information
yukawa committed Jan 31, 2015
1 parent 091dc3b commit 6895df1
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 173 deletions.
1 change: 0 additions & 1 deletion src/base/base_test.gyp
Expand Up @@ -126,7 +126,6 @@
'sources': [
'bitarray_test.cc',
'flags_test.cc',
'hash_tables_test.cc',
'iterator_adapter_test.cc',
'logging_test.cc',
'mmap_test.cc',
Expand Down
70 changes: 0 additions & 70 deletions src/base/hash_tables.h

This file was deleted.

43 changes: 0 additions & 43 deletions src/base/hash_tables_test.cc

This file was deleted.

4 changes: 2 additions & 2 deletions src/data_manager/data_manager_test_base.cc
Expand Up @@ -31,11 +31,11 @@

#include <cstring>
#include <string>
#include <unordered_set>
#include <vector>

#include "base/file_stream.h"
#include "base/file_util.h"
#include "base/hash_tables.h"
#include "base/logging.h"
#include "base/util.h"
#include "converter/connector_base.h"
Expand Down Expand Up @@ -210,7 +210,7 @@ void DataManagerTestBase::SuggestionFilterTest_IsBadSuggestion() {
}

// Load the original suggestion filter from file.
hash_set<string> suggestion_filter_set;
std::unordered_set<string> suggestion_filter_set;

vector<string> files;
Util::SplitStringUsing(suggestion_filter_files_, ",", &files);
Expand Down
4 changes: 2 additions & 2 deletions src/dictionary/system/system_dictionary_builder.cc
Expand Up @@ -33,10 +33,10 @@
#include <climits>
#include <cstring>
#include <sstream>
#include <unordered_set>

#include "base/file_stream.h"
#include "base/flags.h"
#include "base/hash_tables.h"
#include "base/logging.h"
#include "base/util.h"
#include "dictionary/dictionary_token.h"
Expand Down Expand Up @@ -202,7 +202,7 @@ bool HasHomonymsInSamePos(
return false;
}

hash_set<uint32> seen;
std::unordered_set<uint32> seen;
for (size_t i = 0; i < key_info.tokens.size(); ++i) {
const Token *token = key_info.tokens[i].token;
const uint32 pos = GetCombinedPos(token->lid, token->rid);
Expand Down
2 changes: 1 addition & 1 deletion src/mozc_version_template.txt
@@ -1,6 +1,6 @@
MAJOR=2
MINOR=16
BUILD=2037
BUILD=2038
REVISION=102
# NACL_DICTIONARY_VERSION is the target version of the system dictionary to be
# downloaded by NaCl Mozc.
Expand Down
6 changes: 3 additions & 3 deletions src/prediction/suggestion_filter_test.cc
Expand Up @@ -30,13 +30,13 @@
#include "prediction/suggestion_filter.h"

#include <set>
#include <vector>
#include <string>
#include <unordered_set>
#include <vector>

#include "base/file_stream.h"
#include "base/file_util.h"
#include "base/flags.h"
#include "base/hash_tables.h"
#include "base/logging.h"
#include "base/util.h"
#include "testing/base/public/googletest.h"
Expand Down Expand Up @@ -69,7 +69,7 @@ const double kErrorRatio = 0.0001;

TEST(SuggestionFilter, IsBadSuggestionTest) {
// Load suggestion_filter
hash_set<string> suggestion_filter_set;
std::unordered_set<string> suggestion_filter_set;

vector<string> files;
Util::SplitStringUsing(FLAGS_suggestion_filter_files, ",", &files);
Expand Down
20 changes: 7 additions & 13 deletions src/win32/tip/tip_text_service.cc
Expand Up @@ -38,9 +38,9 @@

#include <memory>
#include <string>
#include <unordered_map>

#include "base/const.h"
#include "base/hash_tables.h"
#include "base/logging.h"
#include "base/port.h"
#include "base/process.h"
Expand Down Expand Up @@ -239,7 +239,7 @@ CComPtr<ITfCategoryMgr> GetCategoryMgr() {

// Custom hash function for ATL::CComPtr.
template <typename T>
struct CComPtrHashCompare : public hash_compare<CComPtr<T>> {
struct CComPtrHash {
size_t operator()(const CComPtr<T> &value) const {
// Caveats: On x86 environment, both _M_X64 and _M_IX86 are defined. So we
// need to check _M_X64 first.
Expand All @@ -253,20 +253,14 @@ struct CComPtrHashCompare : public hash_compare<CComPtr<T>> {
// Compress the data by shifting unused bits.
return reinterpret_cast<size_t>(value.p) >> kUnusedBits;
}
bool operator()(const CComPtr<T> &value1, const CComPtr<T> &value2) const {
return value1 != value2;
}
};

// Custom hash function for GUID.
struct GuidHashCompare : public hash_compare<GUID> {
struct GuidHash {
size_t operator()(const GUID &value) const {
// Compress the data by shifting unused bits.
return value.Data1;
}
bool operator()(const GUID &value1, const GUID &value2) const {
return !::IsEqualGUID(value1, value2);
}
};

// An observer that binds ITfCompositionSink::OnCompositionTerminated callback
Expand Down Expand Up @@ -1785,10 +1779,10 @@ class TipTextServiceImpl
// Used for LangBar integration.
TipLangBar langbar_;

typedef hash_map<GUID, UINT, GuidHashCompare> PreservedKeyMap;
typedef hash_map<CComPtr<ITfContext>,
TipPrivateContext *,
CComPtrHashCompare<ITfContext>> PrivateContextMap;
using PreservedKeyMap = std::unordered_map<GUID, UINT, GuidHash>;
using PrivateContextMap = std::unordered_map<CComPtr<ITfContext>,
TipPrivateContext *,
CComPtrHash<ITfContext>>;
PrivateContextMap private_context_map_;
PreservedKeyMap preserved_key_map_;
unique_ptr<TipThreadContext> thread_context_;
Expand Down
6 changes: 2 additions & 4 deletions src/win32/tip/tip_ui_element_immersive.cc
Expand Up @@ -40,8 +40,8 @@
#include <msctf.h>

#include <memory>
#include <unordered_map>

#include "base/hash_tables.h"
#include "base/util.h"
#include "renderer/table_layout.h"
#include "renderer/win32/text_renderer.h"
Expand Down Expand Up @@ -607,9 +607,7 @@ HWND GetOwnerWindow(ITfContext *context) {
return window_handle;
}

class WindowMap
: public hash_map<HWND, TipImmersiveUiElementImpl *> {
};
using WindowMap = std::unordered_map<HWND, TipImmersiveUiElementImpl *>;

class ThreadLocalInfo {
public:
Expand Down
6 changes: 4 additions & 2 deletions src/win32/tip/tip_ui_element_manager.cc
Expand Up @@ -36,7 +36,8 @@
#include <atlstr.h>
#include <msctf.h>

#include "base/hash_tables.h"
#include <unordered_map>

#include "renderer/renderer_command.pb.h"
#include "session/commands.pb.h"
#include "win32/base/input_state.h"
Expand Down Expand Up @@ -93,7 +94,8 @@ HRESULT EndUI(ITfUIElementMgr *ui_element_manager, DWORD element_id) {
} // namespace

class TipUiElementManager::UiElementMap
: public hash_map<TipUiElementManager::UIElementFlags, UIElementInfo> {
: public std::unordered_map<TipUiElementManager::UIElementFlags,
UIElementInfo> {
};

TipUiElementManager::TipUiElementManager()
Expand Down
35 changes: 3 additions & 32 deletions src/win32/tip/tip_ui_handler_immersive.cc
Expand Up @@ -38,7 +38,8 @@
#include <atlwin.h>
#include <msctf.h>

#include "base/hash_tables.h"
#include <unordered_map>

#include "base/util.h"
#include "session/commands.pb.h"
#include "win32/tip/tip_composition_util.h"
Expand Down Expand Up @@ -74,37 +75,7 @@ volatile bool g_module_unloaded = false;
// value, the current thread is initialized.
volatile DWORD g_tls_index = TLS_OUT_OF_INDEXES;

// Visual C++ 2008 requires this.
#if 1310 <= _MSC_VER || _MSC_VER < 1600
using stdext::hash_compare;
#endif // 1310 <= _MSC_VER < 1600

// Custom hash function for ATL::CComPtr.
template <typename T>
struct PtrHashCompare : public hash_compare<T> {
std::size_t operator()(const T &value) const {
// Caveats: On x86 environment, both _M_X64 and _M_IX86 are defined. So we
// need to check _M_X64 first.
#if defined(_M_X64)
const size_t kUnusedBits = 3; // assuming 8-byte aligned
#elif defined(_M_IX86)
const size_t kUnusedBits = 2; // assuming 4-byte aligned
#else
#error "unsupported platform"
#endif
// Compress the data by shifting unused bits.
return reinterpret_cast<size_t>(value) >> kUnusedBits;
}
bool operator()(const T &value1, const T &value2) const {
return value1 != value2;
}
};

class UiElementMap
: public hash_map<ITfUIElement *,
HWND,
PtrHashCompare<IUnknown *> > {
};
using UiElementMap = std::unordered_map<ITfUIElement *, HWND>;

class ThreadLocalInfo {
public:
Expand Down

0 comments on commit 6895df1

Please sign in to comment.