]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Some minor optimizations
authorterencehill <piuntn@gmail.com>
Fri, 1 Feb 2019 23:00:56 +0000 (00:00 +0100)
committerterencehill <piuntn@gmail.com>
Fri, 1 Feb 2019 23:00:56 +0000 (00:00 +0100)
qcsrc/common/command/markup.qc
qcsrc/common/util.qc
qcsrc/menu/item/inputbox.qc
qcsrc/menu/menu.qc
qcsrc/menu/xonotic/serverlist.qc

index 95a3b53c54b9950b7b7dc525669c40b583f08895..1618f6e08f8053828637e62dda1e6e18b2972b39 100644 (file)
@@ -66,7 +66,8 @@ string GenericCommand_markup(string s2)
 
        red = 0;
        ccase = 0;
-       for(i = 0; i < strlen(s2); ++i)
+       int len = strlen(s2);
+       for (i = 0; i < len; ++i)
        {
                for(j = 0; j < NUM_MARKUPS; ++j)
                {
index a7e9c42104d222e04d7b6d1d5884c6376eb7b060..66cd016c0ae90746bb584339f65400e41114c1f8 100644 (file)
@@ -217,7 +217,8 @@ void wordwrap_cb(string s, float l, void(string) callback)
 
        s = strzone(s);
        lleft = l;
-       for (i = 0;i < strlen(s);++i)
+       int len = strlen(s);
+       for (i = 0; i < len; ++i)
        {
                if (substring(s, i, 2) == "\\n")
                {
@@ -235,12 +236,12 @@ void wordwrap_cb(string s, float l, void(string) callback)
                        if (lleft > 0)
                        {
                                callback(" ");
-                               lleft = lleft - 1;
+                               --lleft;
                        }
                }
                else
                {
-                       for (j = i+1;j < strlen(s);++j)
+                       for (j = i+1; j < len; ++j)
                                //    ^^ this skips over the first character of a word, which
                                //       is ALWAYS part of the word
                                //       this is safe since if i+1 == strlen(s), i will become
@@ -268,7 +269,7 @@ void wordwrap_cb(string s, float l, void(string) callback)
                                lleft = l;
                        }
                        callback(substring(s, i, wlen));
-                       lleft = lleft - wlen;
+                       lleft -= wlen;
                        i = j - 1;
                }
        }
index 3272ed54f39ec1953ff8e61b822cced36287b414..d19125a218e658fd6c5cf4b45419abb6335906d1 100644 (file)
 
        void InputBox_enterText(entity me, string ch)
        {
-               float i;
-               for (i = 0; i < strlen(ch); ++i)
+               int len = strlen(ch);
+               for (int i = 0; i < len; ++i)
                        if (strstrofs(me.forbiddenCharacters, substring(ch, i, 1), 0) > -1) return;
                if (me.maxLength > 0)
                {
-                       if (strlen(ch) + strlen(me.text) > me.maxLength) return;
+                       if (len + strlen(me.text) > me.maxLength) return;
                }
                else if (me.maxLength < 0)
                {
                        if (u8_strsize(ch) + u8_strsize(me.text) > -me.maxLength) return;
                }
                me.setText(me, strcat(substring(me.text, 0, me.cursorPos), ch, substring(me.text, me.cursorPos, strlen(me.text) - me.cursorPos)));
-               me.cursorPos += strlen(ch);
+               me.cursorPos += len;
        }
 
        float InputBox_keyDown(entity me, float key, float ascii, float shift)
index fb6c4aeeda60a612cbe47ffe4c6804022b315c23..f195574449379ceec441847d1605267878b38789 100644 (file)
@@ -335,7 +335,8 @@ void drawBackground(string img, float a, string algn, float force1)
        if (main.mainNexposee.ModalController_state == 0) return;
        vector v = '0 0 0';
        int scalemode = SCALEMODE_CROP;
-       for (int i = 0, l = 0; i < strlen(algn); ++i)
+       int len = strlen(algn);
+       for (int i = 0, l = 0; i < len; ++i)
        {
                string c = substring(algn, i, 1);
                switch (c)
index b781ff6819b55055b52d06d5288b0a32e3bf4bd1..87c8852a988691e848a20c753501a9a174e445df 100644 (file)
@@ -810,7 +810,7 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is
        vector oldscale = draw_scale;
        vector oldshift = draw_shift;
 #define SET_YRANGE(start,end) \
-       draw_scale = boxToGlobalSize(eX * 1 + eY * (end - start), oldscale); \
+       draw_scale = boxToGlobalSize(eX + eY * (end - start), oldscale); \
        draw_shift = boxToGlobal(eY * start, oldshift, oldscale);
 
        for (j = 0; j < category_draw_count; ++j) {