Remove base parameter from tvCastToInt64InPlace

Nothing uses it, and it means we can't as easily drop
folly::to for int-string conversions into these guys, which I'd like
to try later.  (Non-base-10 conversions are probably much rarer so
it's fine to have different code, I think?)

Also removes tvCastToInt64 and ports its single callsite to cellToInt.
I plan to move the tvCastTo*InPlace to tv_conversions.h (probably
cell-based functions) in upcoming diffs.
Esse commit está contido em:
Jordan DeLong
2013-06-27 14:37:18 -07:00
commit de Sara Golemon
commit 6b92028afd
5 arquivos alterados com 39 adições e 80 exclusões
+34 -70
Ver Arquivo
@@ -110,79 +110,10 @@ void tvCastToBooleanInPlace(TypedValue* tv) {
tv->m_type = KindOfBoolean;
}
void tvCastToInt64InPlace(TypedValue* tv, int base /* = 10 */) {
assert(tvIsPlausible(tv));
tvUnboxIfNeeded(tv);
int64_t i;
switch (tv->m_type) {
case KindOfUninit:
case KindOfNull:
tv->m_data.num = 0LL;
// Fall through
case KindOfBoolean:
assert(tv->m_data.num == 0LL || tv->m_data.num == 1LL);
tv->m_type = KindOfInt64;
// Fall through
case KindOfInt64:
return;
case KindOfDouble: {
i = toInt64(tv->m_data.dbl);
break;
}
case KindOfStaticString: i = (tv->m_data.pstr->toInt64(base)); break;
case KindOfString: {
i = (tv->m_data.pstr->toInt64(base));
tvDecRefStr(tv);
break;
}
case KindOfArray: {
i = (tv->m_data.parr->empty() ? 0LL : 1LL);
tvDecRefArr(tv);
break;
}
case KindOfObject: {
i = (tv->m_data.pobj ? tv->m_data.pobj->o_toInt64() : 0LL);
tvDecRefObj(tv);
break;
}
default: assert(false); i = 0LL; break;
}
tv->m_data.num = i;
tv->m_type = KindOfInt64;
}
int64_t tvCastToInt64(TypedValue* tv, int base /* = 10 */) {
assert(tvIsPlausible(tv));
if (tv->m_type == KindOfRef) {
tv = tv->m_data.pref->tv();
}
switch (tv->m_type) {
case KindOfUninit:
case KindOfNull:
return 0;
case KindOfBoolean:
assert(tv->m_data.num == 0LL || tv->m_data.num == 1LL);
// Fall through
case KindOfInt64:
return tv->m_data.num;
case KindOfDouble:
return toInt64(tv->m_data.dbl);
case KindOfStaticString:
case KindOfString:
return tv->m_data.pstr->toInt64(base);
case KindOfArray:
return tv->m_data.parr->empty() ? 0 : 1;
case KindOfObject:
return tv->m_data.pobj->o_toInt64();
default:
not_reached();
}
}
void tvCastToDoubleInPlace(TypedValue* tv) {
assert(tvIsPlausible(tv));
tvUnboxIfNeeded(tv);
double d;
switch (tv->m_type) {
case KindOfUninit:
@@ -208,6 +139,39 @@ void tvCastToDoubleInPlace(TypedValue* tv) {
tv->m_type = KindOfDouble;
}
void cellCastToInt64InPlace(Cell* cell) {
assert(cellIsPlausible(cell));
int64_t i;
switch (cell->m_type) {
case KindOfUninit:
case KindOfNull:
cell->m_data.num = 0LL;
// Fall through
case KindOfBoolean:
assert(cell->m_data.num == 0LL || cell->m_data.num == 1LL);
cell->m_type = KindOfInt64;
// Fall through
case KindOfInt64:
return;
case KindOfDouble: {
i = toInt64(cell->m_data.dbl);
break;
}
case KindOfStaticString: i = (cell->m_data.pstr->toInt64()); break;
case KindOfString: {
i = cell->m_data.pstr->toInt64();
tvDecRefStr(cell);
break;
}
}
void tvCastToInt64InPlace(TypedValue* tv) {
assert(tvIsPlausible(tv));
tvUnboxIfNeeded(tv);
cellCastToInt64InPlace(tv);
}
double tvCastToDouble(TypedValue* tv) {
assert(tvIsPlausible(tv));
if (tv->m_type == KindOfRef) {
+1 -2
Ver Arquivo
@@ -464,8 +464,7 @@ void tvUnboxIfNeeded(TypedValue* tv);
* old value, if necessary).
*/
void tvCastToBooleanInPlace(TypedValue* tv);
void tvCastToInt64InPlace(TypedValue* tv, int base = 10);
int64_t tvCastToInt64(TypedValue* tv, int base = 10);
void tvCastToInt64InPlace(TypedValue* tv);
void tvCastToDoubleInPlace(TypedValue* tv);
double tvCastToDouble(TypedValue* tv);
void tvCastToStringInPlace(TypedValue* tv);
-2
Ver Arquivo
@@ -3597,8 +3597,6 @@ void CodeGenerator::cgCastStk(IRInstruction *inst) {
if (type.subtypeOf(Type::Bool)) {
tvCastHelper = (TCA)tvCastToBooleanInPlace;
} else if (type.subtypeOf(Type::Int)) {
// if casting to integer, pass 10 as the base for the conversion
args.imm(10);
tvCastHelper = (TCA)tvCastToInt64InPlace;
} else if (type.subtypeOf(Type::Dbl)) {
tvCastHelper = (TCA)tvCastToDoubleInPlace;
+2 -1
Ver Arquivo
@@ -158,7 +158,8 @@ int64_t convStrToIntHelper(const StringData* s) {
}
int64_t convCellToIntHelper(TypedValue tv) {
return tvCastToInt64(&tv);
// TODO call cellToInt directly from the TC.
return cellToInt(tv);
}
ObjectData* convCellToObjHelper(TypedValue tv) {
+2 -5
Ver Arquivo
@@ -24,6 +24,7 @@
#include "hphp/runtime/vm/core_types.h"
#include "hphp/runtime/vm/runtime.h"
#include "hphp/runtime/ext/ext_collections.h"
#include "hphp/runtime/base/tv_conversions.h"
namespace HPHP {
@@ -642,11 +643,7 @@ template<KeyType keyType>
inline int64_t castKeyToInt(TypedValue* key) {
TypedValue scratch;
initScratchKey<keyType>(scratch, key);
if (key->m_type == KindOfInt64) {
return key->m_data.num;
} else {
return tvCastToInt64(key);
}
return cellToInt(*tvToCell(key));
}
template<>