]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Optimize a check
authorterencehill <piuntn@gmail.com>
Sun, 13 Nov 2011 18:12:10 +0000 (19:12 +0100)
committerterencehill <piuntn@gmail.com>
Sun, 13 Nov 2011 18:12:10 +0000 (19:12 +0100)
qcsrc/common/util.qc
qcsrc/menu/xonotic/colorpicker.c

index 5ffef8f092052aeb4361799d5d63ed0d34663e3c..e10e8f20fdb9bd0d03922081e9aebfb1a0e5e77d 100644 (file)
@@ -1296,7 +1296,7 @@ string find_last_color_code(string s)
                        ++carets;
 
                // check if carets aren't all escaped
-               if (carets == 1 || mod(carets, 2) == 1) // first check is just an optimization
+               if (carets & 1)
                {
                        if(i+1 <= len)
                        if(strstrofs("0123456789", substring(s, i+1, 1), 0) >= 0)
index 781ca9a44fb17460ee588a19ec97596ac2d90569..b9341851001f0a5af5b4f512e55f1d7c145d09b1 100644 (file)
@@ -83,7 +83,7 @@ float XonoticColorpicker_mouseDrag(entity me, vector coords)
                                carets = 1;
                                while (i - 2 - carets >= 0 && substring(me.controlledTextbox.text, i - 2 - carets, 1) == "^")
                                        ++carets;
-                               if (carets == 1 || mod(carets, 2) == 1) // first check is just an optimization
+                               if (carets & 1)
                                        if(strstrofs("0123456789", substring(me.controlledTextbox.text, i-1, 1), 0) >= 0)
                                        {
                                                me.controlledTextbox.keyDown(me.controlledTextbox, K_BACKSPACE, 8, 0);
@@ -100,7 +100,7 @@ float XonoticColorpicker_mouseDrag(entity me, vector coords)
                                carets = 1;
                                while (i - 5 - carets >= 0 && substring(me.controlledTextbox.text, i - 5 - carets, 1) == "^")
                                        ++carets;
-                               if (carets == 1 || mod(carets, 2) == 1) // first check is just an optimization
+                               if (carets & 1)
                                        if(strstrofs("0123456789abcdefABCDEF", substring(me.controlledTextbox.text, i-3, 1), 0) >= 0)
                                                if(strstrofs("0123456789abcdefABCDEF", substring(me.controlledTextbox.text, i-2, 1), 0) >= 0)
                                                        if(strstrofs("0123456789abcdefABCDEF", substring(me.controlledTextbox.text, i-1, 1), 0) >= 0)
@@ -122,7 +122,7 @@ float XonoticColorpicker_mouseDrag(entity me, vector coords)
                carets = 1;
                while (i - 1 - carets >= 0 && substring(me.controlledTextbox.text, i - 1 - carets, 1) == "^")
                        ++carets;
-               if (carets == 1 || mod(carets, 2) == 1) // first check is just an optimization
+               if (carets & 1)
                        me.controlledTextbox.enterText(me.controlledTextbox, "^"); // escape previous caret
        }