From: terencehill Date: Fri, 1 Feb 2019 23:00:56 +0000 (+0100) Subject: Some minor optimizations X-Git-Tag: xonotic-v0.8.5~1618 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=ca43a51345c0e7d23b862eac0f7ea292800f9aa8;p=xonotic%2Fxonotic-data.pk3dir.git Some minor optimizations --- diff --git a/qcsrc/common/command/markup.qc b/qcsrc/common/command/markup.qc index 95a3b53c5..1618f6e08 100644 --- a/qcsrc/common/command/markup.qc +++ b/qcsrc/common/command/markup.qc @@ -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) { diff --git a/qcsrc/common/util.qc b/qcsrc/common/util.qc index a7e9c4210..66cd016c0 100644 --- a/qcsrc/common/util.qc +++ b/qcsrc/common/util.qc @@ -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; } } diff --git a/qcsrc/menu/item/inputbox.qc b/qcsrc/menu/item/inputbox.qc index 3272ed54f..d19125a21 100644 --- a/qcsrc/menu/item/inputbox.qc +++ b/qcsrc/menu/item/inputbox.qc @@ -106,19 +106,19 @@ 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) diff --git a/qcsrc/menu/menu.qc b/qcsrc/menu/menu.qc index fb6c4aeed..f19557444 100644 --- a/qcsrc/menu/menu.qc +++ b/qcsrc/menu/menu.qc @@ -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) diff --git a/qcsrc/menu/xonotic/serverlist.qc b/qcsrc/menu/xonotic/serverlist.qc index b781ff681..87c8852a9 100644 --- a/qcsrc/menu/xonotic/serverlist.qc +++ b/qcsrc/menu/xonotic/serverlist.qc @@ -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) {