-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathName.cpp
More file actions
73 lines (69 loc) · 1.43 KB
/
Copy pathName.cpp
File metadata and controls
73 lines (69 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "Name.h"
#include <mutex>
namespace sh::core
{
std::unordered_map<std::size_t, std::string> Name::map{};
std::shared_mutex Name::mu{};
Name::Name(std::string_view str) :
hash(Util::ConstexprHash(str))
{
#if SH_DEBUG
debugString = str;
#endif
{
std::shared_lock lock{ mu };
auto it = map.find(hash);
if (it != map.end())
return;
}
// 새로운 문자열을 쓰는 작업은 정말 드물게 일어날 것으로 예상된다.
{
std::unique_lock uniqueLock{ mu };
if (map.find(hash) == map.end())
map.insert({ hash, std::string{str} });
}
}
Name::Name(const Name& other) noexcept :
hash(other.hash)
#if SH_DEBUG
, debugString(other.debugString)
#endif
{
}
Name::Name(Name&& other) noexcept :
hash(other.hash)
#if SH_DEBUG
, debugString(std::move(other.debugString))
#endif
{
}
Name::~Name()
{
}
SH_CORE_API auto Name::operator=(const Name& other) noexcept -> Name&
{
hash = other.hash;
#if SH_DEBUG
debugString = other.debugString;
#endif
return *this;
}
SH_CORE_API auto Name::operator=(Name&& other) noexcept -> Name&
{
hash = other.hash;
#if SH_DEBUG
debugString = std::move(other.debugString);
#endif
return *this;
}
SH_CORE_API Name::operator const std::string& () const
{
return ToString();
}
SH_CORE_API auto Name::ToString() const -> const std::string&
{
std::shared_lock lock{ mu };
const std::string& result = map[hash];
return result;
}
}//namespace