diff --git a/src/string_db.cc b/src/string_db.cc deleted file mode 100644 index 0abb2720..00000000 --- a/src/string_db.cc +++ /dev/null @@ -1,40 +0,0 @@ -#if false -#include "string_db.h" - -StringStorage::~StringStorage() { - if (owns_str) { - free((void*)str); - str = nullptr; - owns_str= false; - } -} - -StringStorage StringStorage::CreateUnowned(const char* data, size_t len) { - StringStorage result; - result.str = data; - result.len = len; - result.owns_str = false; - return result; -} - -void StringStorage::Copy() const { - // Copy - char* new_str = (char*)malloc(len + 1); - strncpy(new_str, str, len + 1); - // Assign - str = new_str; - owns_str = true; -} - -bool StringStorage::operator==(const StringStorage& that) const { - return len == that.len && strcmp(str, that.str) == 0; -} - -bool StringStorage::operator!=(const StringStorage& that) const { - return !(*this == that); -} - -bool StringStorage::operator<(const StringStorage& that) const { - return strcmp(str, that.str); -} -#endif \ No newline at end of file diff --git a/src/string_db.h b/src/string_db.h deleted file mode 100644 index 14f1d403..00000000 --- a/src/string_db.h +++ /dev/null @@ -1,154 +0,0 @@ -#if false -#pragma once - -#include "buffer.h" -#include "utils.h" - -#include - -#include -#include -#include -#include -#include -#include - - -template -struct StringView { - StringView(); - StringView(const StringView& that); - StringView(const char* str, size_t len); - - bool operator==(const StringView& that) const; - bool operator!=(const StringView& that) const; - bool operator<(const StringView& that) const; - StringView& operator=(const StringView& that); - - std::string AsString() const; - - size_t len; - const char* str; -}; -// See MAKE_HASHABLE for QueryUsr, IndexUsr - -struct StringStorage { - ~StringStorage(); - - static StringStorage CreateUnowned(const char* str, size_t len); - void Copy() const; - - bool operator==(const StringStorage& that) const; - bool operator!=(const StringStorage& that) const; - bool operator<(const StringStorage& that) const; - - size_t len; - mutable const char* str; - mutable bool owns_str; -}; -MAKE_HASHABLE(StringStorage, t.len, t.str); - -template -struct StringDb { - TStringView GetString(const char* str, size_t len); - TStringView GetString(const std::string& str); - TStringView GetString(CXString cx_string); - - std::unordered_set data_; -}; - - - - - - - - -struct _DummyQueryType {}; -struct _DummyIndexType {}; - -using QueryUsr = StringView<_DummyQueryType>; -using QueryStringDb = StringDb<_DummyQueryType>; - -using IndexUsr = StringView<_DummyIndexType>; -using IndexStringDb = StringDb<_DummyIndexType>; - - - -// TODO: See if we can move this next to StringView definition. -MAKE_HASHABLE(QueryUsr, t.len, t.str); -MAKE_HASHABLE(IndexUsr, t.len, t.str); - - - - - - - - - - - - - -template -StringView::StringView() : len(0), str(nullptr) {} - -template -StringView::StringView(const StringView& that) : len(that.len), str(that.str) {} - -template -StringView::StringView(const char* str, size_t len) : len(len), str(str) {} - -template -bool StringView::operator==(const StringView& that) const { - return len == that.len && strcmp(str, that.str) == 0; -} - -template -bool StringView::operator!=(const StringView& that) const { - return !(*this == that); -} - -template -bool StringView::operator<(const StringView& that) const { - return strcmp(str, that.str); -} - -template -StringView& StringView::operator=(const StringView& that) { - len = that.len; - str = that.str; - return *this; -} - -template -std::string StringView::AsString() const { - return std::string(str, len); -} - -template -TStringView StringDb::GetString(const char* str, size_t len) { - StringStorage lookup = StringStorage::CreateUnowned(str, len); - - auto it = data_.insert(lookup); - if (it.second) - it.first->Copy(); - - return TStringView(it.first->str, it.first->len); -} - -template -TStringView StringDb::GetString(const std::string& str) { - return GetString(str.c_str()); -} - -template -TStringView StringDb::GetString(CXString cx_string) { - assert(cx_string.data); - const char* str = clang_getCString(cx_string); - StringView result = GetString(str); - clang_disposeString(cx_string); - return result; -} -#endif \ No newline at end of file