Codemod asserts to assertxs in the runtime
[hiphop-php.git] / hphp / runtime / base / req-root.cpp
blob104159b3ffe82a6e7ae6cfd1d7f21d5908b9bbdf
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/base/req-root.h"
18 #include "hphp/runtime/base/typed-value.h"
19 #include "hphp/runtime/base/type-string.h"
20 #include "hphp/runtime/base/type-array.h"
21 #include "hphp/runtime/base/type-object.h"
22 #include "hphp/runtime/base/type-variant.h"
23 #include "hphp/runtime/base/ini-setting.h"
24 #include "hphp/util/safe-cast.h"
26 namespace HPHP {
27 namespace req {
29 uint32_t req::root_handle::addRootHandle() {
30 auto& handles = tl_heap->m_root_handles;
31 auto id = safe_cast<uint32_t>(handles.size());
32 handles.push_back(this);
33 return id;
36 uint32_t req::root_handle::stealRootHandle(root_handle* s) {
37 assertx(s->m_id != INVALID);
38 auto& handles = tl_heap->m_root_handles;
39 auto id = s->m_id;
40 handles[id] = this;
41 s->m_id = INVALID;
42 return id;
45 void req::root_handle::delRootHandle() {
46 auto& handles = tl_heap->m_root_handles;
47 auto last = handles.back();
48 handles[last->m_id = m_id] = last;
49 m_id = INVALID;
50 handles.pop_back();
53 template<class T> void root<T>::scan(type_scan::Scanner& scanner) const {
54 scanner.scan(*static_cast<const T*>(this));
57 template<class T> void root<T>::detach() {
58 T::detach();
61 template<> void req::root<TypedValue>::scan(type_scan::Scanner& scanner) const {
62 scanner.scan(*static_cast<const TypedValue*>(this));
65 template<> void req::root<TypedValue>::detach() {
66 m_type = KindOfNull;
69 template struct root<String>;
70 template struct root<Array>;
71 template struct root<Object>;
72 template struct root<Variant>;
73 template struct root<IniSettingMap>;