2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #include "hphp/runtime/vm/litstr-table.h"
19 #include "hphp/runtime/vm/repo-file.h"
20 #include "hphp/runtime/vm/unit.h"
23 ///////////////////////////////////////////////////////////////////////////////
25 LitstrTable
* LitstrTable::s_litstrTable
= nullptr;
27 ///////////////////////////////////////////////////////////////////////////////
29 Id
LitstrTable::mergeLitstr(const StringData
* litstr
) {
35 LitstrMap::const_accessor acc
;
36 if (m_litstr2id
.find(acc
, litstr
)) {
41 auto const sd
= makeStaticString(litstr
);
42 LitstrMap::accessor acc
;
43 if (m_litstr2id
.insert(acc
, sd
)) {
44 acc
->second
= m_nextId
.fetch_add(1, std::memory_order_relaxed
);
50 void LitstrTable::setReading() {
51 always_assert(!m_safeToRead
);
52 always_assert(!m_namedInfo
.size());
54 m_namedInfo
.resize(m_litstr2id
.size() + 1);
55 m_namedInfo
.shrink_to_fit();
56 for (auto const& strId
: m_litstr2id
) {
57 m_namedInfo
[strId
.second
] = LowStringPtr
{strId
.first
};
63 void LitstrTable::forEachLitstr(
64 std::function
<void (int, const StringData
*)> onItem
) {
65 assertx(m_safeToRead
);
67 for (auto& s
: m_namedInfo
) {
75 ///////////////////////////////////////////////////////////////////////////////
78 StringData
* loadLitstrById(Id id
) {
79 if (RuntimeOption::RepoAuthoritative
) return RepoFile::loadLitstr(id
);
83 ///////////////////////////////////////////////////////////////////////////////