Add sub-controls for Hack array compat runtime checks
[hiphop-php.git] / hphp / runtime / base / apc-local-array-defs.h
blob04526ff882227e9dd3df33839410ac36c106a6c2
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2013 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 +----------------------------------------------------------------------+
16 #ifndef incl_HPHP_APC_LOCAL_ARRAY_DEFS_H_
17 #define incl_HPHP_APC_LOCAL_ARRAY_DEFS_H_
19 #include "hphp/runtime/base/apc-local-array.h"
20 #include "hphp/runtime/base/mixed-array-defs.h"
21 #include "hphp/runtime/base/memory-manager.h"
23 namespace HPHP {
25 //////////////////////////////////////////////////////////////////////
27 inline APCLocalArray::APCLocalArray(const APCArray* source)
28 : ArrayData(kApcKind)
29 , m_arr(source)
31 m_size = m_arr->size();
32 source->reference();
33 tl_heap->addApcArray(this);
34 memset(localCache(), KindOfUninit, m_size * sizeof(TypedValue));
35 assert(hasExactlyOneRef());
38 inline size_t APCLocalArray::heapSize() const {
39 return sizeof(*this) + m_size * sizeof(TypedValue);
42 inline APCLocalArray* APCLocalArray::Make(const APCArray* aa) {
43 auto size = sizeof(APCLocalArray) + aa->size() * sizeof(TypedValue);
44 auto local = new (tl_heap->objMalloc(size)) APCLocalArray(aa);
45 assert(local->heapSize() == size);
46 return local;
49 ALWAYS_INLINE
50 APCLocalArray* APCLocalArray::asApcArray(ArrayData* ad) {
51 assert(ad->kind() == kApcKind);
52 return static_cast<APCLocalArray*>(ad);
55 ALWAYS_INLINE
56 const APCLocalArray* APCLocalArray::asApcArray(const ArrayData* ad) {
57 assert(ad->kind() == kApcKind);
58 return static_cast<const APCLocalArray*>(ad);
61 inline TypedValue* APCLocalArray::localCache() const {
62 return const_cast<TypedValue*>(
63 reinterpret_cast<const TypedValue*>(this + 1)
67 inline void APCLocalArray::scan(type_scan::Scanner& scanner) const {
68 scanner.scan(*localCache(), m_size * sizeof(TypedValue));
71 //////////////////////////////////////////////////////////////////////
75 #endif