From ab423f99c6abf7cddb88e4e2dbf5475d7545d114 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Fri, 9 Dec 2016 21:18:06 +0000 Subject: [PATCH] Optimising retrieval of sector_floorpic/ceilingpic As LJSonic has pointed out, there's no need for a for loop in either case; just use sector->floorpic/ceilingpic as a levelflats index directly (Besides, if that was to stop any out-of-bounds indexes being used, that's hardly the way to do it anyway) --- src/lua_maplib.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/lua_maplib.c b/src/lua_maplib.c index 54614c4e..208aebe3 100644 --- a/src/lua_maplib.c +++ b/src/lua_maplib.c @@ -348,22 +348,12 @@ static int sector_get(lua_State *L) case sector_ceilingheight: lua_pushfixed(L, sector->ceilingheight); return 1; - case sector_floorpic: { // floorpic - levelflat_t *levelflat; - INT16 i; - for (i = 0, levelflat = levelflats; i != sector->floorpic; i++, levelflat++) - ; - lua_pushlstring(L, levelflat->name, 8); + case sector_floorpic: // floorpic + lua_pushlstring(L, levelflats[sector->floorpic].name, 8); return 1; - } - case sector_ceilingpic: { // ceilingpic - levelflat_t *levelflat; - INT16 i; - for (i = 0, levelflat = levelflats; i != sector->ceilingpic; i++, levelflat++) - ; - lua_pushlstring(L, levelflat->name, 8); + case sector_ceilingpic: // ceilingpic + lua_pushlstring(L, levelflats[sector->ceilingpic].name, 8); return 1; - } case sector_lightlevel: lua_pushinteger(L, sector->lightlevel); return 1;