From 0f334f2870a87bda29e009ef90d7b9174e46a019 Mon Sep 17 00:00:00 2001 From: Patrick Donnelly Date: Sat, 13 Feb 2016 19:59:09 -0500 Subject: [PATCH] lua: use simpler lua_next traversal structure Signed-off-by: Patrick Donnelly --- src/cls/lua/cls_lua.cc | 5 +---- src/mds/Mantle.cc | 4 +--- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/cls/lua/cls_lua.cc b/src/cls/lua/cls_lua.cc index 39506fa9d33..811c1771dad 100644 --- a/src/cls/lua/cls_lua.cc +++ b/src/cls/lua/cls_lua.cc @@ -509,8 +509,7 @@ static int clslua_map_set_vals(lua_State *L) map kvpairs; - lua_pushnil(L); - while (lua_next(L, 1) != 0) { + for (lua_pushnil(L); lua_next(L, 1); lua_pop(L, 1)) { /* * In the case of a numeric key a copy is made on the stack because * converting to a string would otherwise manipulate the original key and @@ -553,8 +552,6 @@ static int clslua_map_set_vals(lua_State *L) } kvpairs[key] = val; - - lua_pop(L, 1); } int ret = cls_cxx_map_set_vals(hctx, &kvpairs); diff --git a/src/mds/Mantle.cc b/src/mds/Mantle.cc index e9a65ef1a0c..d0520c27014 100644 --- a/src/mds/Mantle.cc +++ b/src/mds/Mantle.cc @@ -143,15 +143,13 @@ int Mantle::balance(const string &script, /* fill in return value */ mds_rank_t it = mds_rank_t(0); - lua_pushnil(L); - while (lua_next(L, -2) != 0) { + for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) { if (!lua_isnumber(L, -1)) { dout(0) << "WARNING: mantle script returned a malformed response" << dendl; lua_close(L); return -EINVAL; } my_targets[it] = (lua_tonumber(L, -1)); - lua_pop(L, 1); it++; } -- 2.39.5