Split ArrayData::append(ArrayOp) into plus() and merge()

We had two distinct functions dispatched by an enum that was
always known somewhere higher up on the callstack.
Esse commit está contido em:
Edwin Smith
2013-06-11 17:19:27 -07:00
commit de sgolemon
commit 274ef6c45b
13 arquivos alterados com 107 adições e 84 exclusões
+24 -23
Ver Arquivo
@@ -1415,31 +1415,32 @@ ArrayData *HphpArray::appendWithRef(CVarRef v, bool copy) {
return a->nextInsertWithRef(v);
}
ArrayData* HphpArray::append(const ArrayData* elems, ArrayOp op, bool copy) {
ArrayData* HphpArray::plus(const ArrayData* elems, bool copy) {
HphpArray* a = !copy ? this : copyImpl();
if (op == Plus) {
for (ArrayIter it(elems); !it.end(); it.next()) {
Variant key = it.first();
CVarRef value = it.secondRef();
if (key.isNumeric()) {
a->addValWithRef(key.toInt64(), value);
} else {
a->addValWithRef(key.getStringData(), value);
}
for (ArrayIter it(elems); !it.end(); it.next()) {
Variant key = it.first();
CVarRef value = it.secondRef();
if (key.isNumeric()) {
a->addValWithRef(key.toInt64(), value);
} else {
a->addValWithRef(key.getStringData(), value);
}
} else {
assert(op == Merge);
for (ArrayIter it(elems); !it.end(); it.next()) {
Variant key = it.first();
CVarRef value = it.secondRef();
if (key.isNumeric()) {
a->nextInsertWithRef(value);
} else {
Variant *p;
StringData *sd = key.getStringData();
a->addLvalImpl(sd, sd->hash(), &p);
p->setWithRef(value);
}
}
return a;
}
ArrayData* HphpArray::merge(const ArrayData* elems, bool copy) {
HphpArray* a = !copy ? this : copyImpl();
for (ArrayIter it(elems); !it.end(); it.next()) {
Variant key = it.first();
CVarRef value = it.secondRef();
if (key.isNumeric()) {
a->nextInsertWithRef(value);
} else {
Variant *p;
StringData *sd = key.getStringData();
a->addLvalImpl(sd, sd->hash(), &p);
p->setWithRef(value);
}
}
return a;