From b338524437df5cba754074d49ad1150287d3fc19 Mon Sep 17 00:00:00 2001 From: Shaunak Kishore Date: Wed, 27 Jan 2021 19:12:09 -0800 Subject: [PATCH] Delete getInt / getStr helpers Summary: The reason I didn't use CallSpec::method for these getters before was because ArrayData::get has an optional bool parameter. Let's split out that overload so that we can target the method. colavitam has some inlining changes that dramatically improve these methods. Reviewed By: colavitam Differential Revision: D26076684 fbshipit-source-id: 821b523724e3a96f294ce6cd671523f634a4344b --- hphp/runtime/base/array-data-defs.h | 12 ++++++++++-- hphp/runtime/base/array-data.h | 11 +++++++++-- hphp/runtime/vm/jit/irlower-bespoke.cpp | 19 +++++++------------ 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/hphp/runtime/base/array-data-defs.h b/hphp/runtime/base/array-data-defs.h index 5f742f068e4..bcb637ce8e3 100644 --- a/hphp/runtime/base/array-data-defs.h +++ b/hphp/runtime/base/array-data-defs.h @@ -233,14 +233,22 @@ inline arr_lval ArrayData::lval(TypedValue k) { : lval(detail::getStringKey(k)); } +inline TypedValue ArrayData::get(int64_t k) const { + return g_array_funcs.nvGetInt[kind()](this, k); +} + +inline TypedValue ArrayData::get(const StringData* k) const { + return g_array_funcs.nvGetStr[kind()](this, k); +} + inline TypedValue ArrayData::get(int64_t k, bool error) const { - auto const result = g_array_funcs.nvGetInt[kind()](this, k); + auto const result = get(k); if (error && !result.is_init()) getNotFound(k); return result; } inline TypedValue ArrayData::get(const StringData* k, bool error) const { - auto const result = g_array_funcs.nvGetStr[kind()](this, k); + auto const result = get(k); if (error && !result.is_init()) getNotFound(k); return result; } diff --git a/hphp/runtime/base/array-data.h b/hphp/runtime/base/array-data.h index 8ffdd24b33f..22ccb3c40db 100644 --- a/hphp/runtime/base/array-data.h +++ b/hphp/runtime/base/array-data.h @@ -397,14 +397,21 @@ public: Variant getValue(ssize_t pos) const; /* + * Get the value of the element at key `k'. Returns an Uninit TypedValue if + * the key `k` is missing from the array. + */ + TypedValue get(int64_t k) const; + TypedValue get(const StringData* k) const; + + /* * Get the value of the element at key `k'. * * If `error` is false, get returns an Uninit TypedValue if `k` is missing. * If `error` is true, get throws if `k` is missing. */ + TypedValue get(int64_t k, bool error) const; + TypedValue get(const StringData* k, bool error) const; TypedValue get(TypedValue k, bool error = false) const; - TypedValue get(int64_t k, bool error = false) const; - TypedValue get(const StringData* k, bool error = false) const; TypedValue get(const String& k, bool error = false) const; TypedValue get(const Variant& k, bool error = false) const; diff --git a/hphp/runtime/vm/jit/irlower-bespoke.cpp b/hphp/runtime/vm/jit/irlower-bespoke.cpp index 708ae3c29a9..9b8b72a94da 100644 --- a/hphp/runtime/vm/jit/irlower-bespoke.cpp +++ b/hphp/runtime/vm/jit/irlower-bespoke.cpp @@ -84,16 +84,6 @@ void cgProfileArrLikeProps(IRLS& env, const IRInstruction* inst) { ////////////////////////////////////////////////////////////////////////////// -namespace { -static TypedValue getInt(const ArrayData* ad, int64_t key) { - return ad->get(key); -} - -static TypedValue getStr(const ArrayData* ad, const StringData* key) { - return ad->get(key); -} -} - // This macro returns a CallSpec to one of several static functions: // // - the one on a specific, concrete bespoke layout; @@ -130,11 +120,16 @@ void cgBespokeGet(IRLS& env, const IRInstruction* inst) { using GetInt = TypedValue (ArrayData::*)(int64_t) const; using GetStr = TypedValue (ArrayData::*)(const StringData*) const; + auto const getInt = + CallSpec::method(static_cast(&ArrayData::get)); + auto const getStr = + CallSpec::method(static_cast(&ArrayData::get)); + auto const arr = inst->src(0)->type(); auto const key = inst->src(1)->type(); auto const target = (key <= TInt) - ? CALL_TARGET(arr, NvGetInt, CallSpec::direct(getInt)) - : CALL_TARGET(arr, NvGetStr, CallSpec::direct(getStr)); + ? CALL_TARGET(arr, NvGetInt, getInt) + : CALL_TARGET(arr, NvGetStr, getStr); auto& v = vmain(env); auto const args = argGroup(env, inst).ssa(0).ssa(1); -- 2.11.4.GIT