Compute ambient coeffects and write to coeffects local
[hiphop-php.git] / hphp / runtime / vm / litstr-table.cpp
blob0bb2e3035888a29e844f74bbb02a7e48d1821cc9
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
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.h"
20 #include "hphp/runtime/vm/unit.h"
22 namespace HPHP {
23 ///////////////////////////////////////////////////////////////////////////////
25 LitstrTable* LitstrTable::s_litstrTable = nullptr;
27 ///////////////////////////////////////////////////////////////////////////////
29 Id LitstrTable::mergeLitstr(const StringData* litstr) {
30 if (!litstr) {
31 return 0;
35 LitstrMap::const_accessor acc;
36 if (m_litstr2id.find(acc, litstr)) {
37 return acc->second;
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);
47 return acc->second;
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};
60 m_safeToRead = true;
63 void LitstrTable::forEachLitstr(
64 std::function<void (int, const StringData*)> onItem) {
65 assertx(m_safeToRead);
66 auto i = 0;
67 for (auto& s : m_namedInfo) {
68 if (i != 0) {
69 onItem(i, s.get());
71 i++;
75 ///////////////////////////////////////////////////////////////////////////////
76 // Lazy loading.
78 StringData* loadLitstrById(Id id) {
79 if (RuntimeOption::RepoAuthoritative) {
80 return Repo::get().lsrp().loadOne(id);
82 return nullptr;
85 ///////////////////////////////////////////////////////////////////////////////