EvalEmitDVArray: varray
[hiphop-php.git] / hphp / runtime / base / record-data.cpp
blob3f7f976da892d67632d5f7e46a7c40c7f12099a0
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/record-data.h"
19 #include "hphp/runtime/base/req-vector.h"
20 #include "hphp/runtime/base/tv-comparisons.h"
21 #include "hphp/runtime/base/tv-mutate.h"
22 #include "hphp/runtime/vm/record.h"
24 namespace HPHP {
26 RecordData::RecordData(const RecordDesc* record)
27 : RecordBase(record) {
28 initHeader(HeaderKind::Record, OneReference);
29 static_assert(sizeof(RecordData) == sizeof(RecordBase) + sizeof(Countable),
30 "RecordData must not have any fields of its own");
33 RecordData* RecordData::newRecord(const RecordDesc* rec,
34 uint32_t initSize,
35 const StringData* const* keys,
36 const TypedValue* values) {
37 return newRecordImpl<RecordData>(rec, initSize, keys, values);
40 RecordData* RecordData::copyRecord() const {
41 auto const rd = copyRecordBase(this, AllocMode::Request);
42 rd->initHeader(this->kind(), OneReference);
43 return rd;
46 NEVER_INLINE
47 void RecordData::release() noexcept {
48 assertx(kindIsValid());
49 auto const numRecFields = m_record->numFields();
50 auto const recFields = fieldVec();
51 for (auto idx = 0; idx < numRecFields; ++idx) {
52 tvDecRefGen(recFields[idx]);
54 tl_heap->objFree(this, heapSize());
55 AARCH64_WALKABLE_FRAME();
58 template<bool(*fieldEq)(TypedValue, TypedValue)>
59 ALWAYS_INLINE
60 bool RecordData::equalImpl(const RecordData* r1, const RecordData* r2) {
61 if (r1->m_record != r2->m_record) {
62 return false;
64 auto const fv1 = r1->fieldVec();
65 auto const fv2 = r2->fieldVec();
66 auto const numFields = r1->m_record->numFields();
67 for (size_t i = 0; i < numFields; ++i) {
68 if (!fieldEq(fv1[i], fv2[i])) {
69 return false;
72 return true;
76 bool RecordData::equal(const RecordData* r1, const RecordData* r2) {
77 return equalImpl<tvEqual>(r1, r2);
79 bool RecordData::same(const RecordData* r1, const RecordData* r2) {
80 return equalImpl<tvSame>(r1, r2);