diff options
author | Albert Krewinkel <albert@zeitkraut.de> | 2017-08-13 14:23:25 +0200 |
---|---|---|
committer | Albert Krewinkel <albert@zeitkraut.de> | 2017-08-13 14:25:36 +0200 |
commit | b9c7adf02ee5da08e97746e9638ddcb162ff651d (patch) | |
tree | 417f19f013190bf29eb8dc4b795fbe626f2e605f /src/Text/Pandoc/Lua/Util.hs | |
parent | 2dc3dbd68b557cbd8974b9daf84df3d26ab5f843 (diff) |
Text.Pandoc.Lua: Optimize performance by using raw table access
Raw table accessing functions never call back into haskell, which allows
the compiler to use more aggressive optimizations. This improves lua
filter performance considerably (⪆5% speedup).
Diffstat (limited to 'src/Text/Pandoc/Lua/Util.hs')
-rw-r--r-- | src/Text/Pandoc/Lua/Util.hs | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/src/Text/Pandoc/Lua/Util.hs b/src/Text/Pandoc/Lua/Util.hs index 9e72b652c..1b6338e64 100644 --- a/src/Text/Pandoc/Lua/Util.hs +++ b/src/Text/Pandoc/Lua/Util.hs @@ -31,7 +31,6 @@ Lua utility functions. module Text.Pandoc.Lua.Util ( adjustIndexBy , getTable - , setTable , addValue , getRawInt , setRawInt @@ -43,7 +42,7 @@ module Text.Pandoc.Lua.Util import Foreign.Lua (Lua, FromLuaStack (..), ToLuaStack (..), NumArgs, StackIndex, getglobal') -import Foreign.Lua.Api (call, gettable, pop, rawgeti, rawseti, settable) +import Foreign.Lua.Api (call, pop, rawget, rawgeti, rawset, rawseti) -- | Adjust the stack index, assuming that @n@ new elements have been pushed on -- the stack. @@ -57,19 +56,15 @@ adjustIndexBy idx n = getTable :: (ToLuaStack a, FromLuaStack b) => StackIndex -> a -> Lua b getTable idx key = do push key - gettable (idx `adjustIndexBy` 1) + rawget (idx `adjustIndexBy` 1) peek (-1) <* pop 1 --- | Set value for key for table at the given index -setTable :: (ToLuaStack a, ToLuaStack b) => StackIndex -> a -> b -> Lua () -setTable idx key value = do - push key - push value - settable (idx `adjustIndexBy` 2) - -- | Add a key-value pair to the table at the top of the stack addValue :: (ToLuaStack a, ToLuaStack b) => a -> b -> Lua () -addValue = setTable (-1) +addValue key value = do + push key + push value + rawset (-3) -- | Get value behind key from table at given index. getRawInt :: FromLuaStack a => StackIndex -> Int -> Lua a |