TelegramMessenger / telemint

Telegram Auction Platform smart contracts
GNU General Public License v3.0
345 stars 71 forks source link

common.fc: slightly optimize store_text #19

Closed loskutov closed 2 years ago

loskutov commented 2 years ago

This way it's (arguably) more readable and consumes slightly less gas:

diff --git a/a b/b
index e111ab1..d557726 100644
--- a/a
+++ b/b
@@ -1,16 +1,12 @@
   store_text PROCINLINE:<{
     //  b text
-    DUP //  b text text
-    SBITS       //  b text len
-    8 PUSHINT   //  b text len _5=8
-    MOD //  b text _6
-    0 EQINT     //  b text _8
-    201 THROWIFNOT
-    DUP //  b text text
-    SBITS       //  b text _10
-    3 RSHIFT#   //  b text _12
-    ROT //  text _12 b
-    8 STU       //  text _14
-    SWAP        //  _14 text
-    STSLICER    //  _15
+    DUP        //  b text text
+    SBITS      //  b text _4
+    8 PUSHINT  //  b text _4 _5=8
+    DIVMOD     //  b text len rem
+    201 THROWIF
+    ROT        //  text len b
+    8 STU      //  text _10
+    SWAP       //  _10 text
+    STSLICER   //  _11
   }>