]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
lua: use simpler lua_next traversal structure 11958/head
authorPatrick Donnelly <batrick@batbytes.com>
Sun, 14 Feb 2016 00:59:09 +0000 (19:59 -0500)
committerPatrick Donnelly <pdonnell@redhat.com>
Mon, 14 Nov 2016 02:55:53 +0000 (21:55 -0500)
Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
src/cls/lua/cls_lua.cc
src/mds/Mantle.cc

index 39506fa9d33bb3d9c222cc4a4bef553e47e51d8a..811c1771dade97b4077faa0a70d165409608318e 100644 (file)
@@ -509,8 +509,7 @@ static int clslua_map_set_vals(lua_State *L)
 
   map<string, bufferlist> 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);
index e9a65ef1a0cba4a71a8b2a1e87ec1eb16ed6f9d4..d0520c27014b6acc8cf1c0cb58bc3659153b8f98 100644 (file)
@@ -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++;
   }