]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
Optimize compiler code generation for 'strlen()'
authorlainon <GermanAizek@yandex.ru>
Wed, 21 Sep 2022 12:41:18 +0000 (15:41 +0300)
committerlainon <GermanAizek@yandex.ru>
Wed, 21 Sep 2022 12:41:18 +0000 (15:41 +0300)
14 files changed:
ar.cpp
cputest_support.cpp
disk.cpp
inputdevice.cpp
isofs.cpp
memory.cpp
od-win32/blkdev_win32_ioctl.cpp
od-win32/debug_win32.cpp
od-win32/hardfile_win32.cpp
od-win32/rp.cpp
od-win32/writelog.cpp
readcpu.cpp
rommgr.cpp
scsitape.cpp

diff --git a/ar.cpp b/ar.cpp
index 0846d501786c4a5b6b64526ca8bfda2f089487e9..50e48469d81a220f1e7c00349dd8b9a5feca58c6 100644 (file)
--- a/ar.cpp
+++ b/ar.cpp
@@ -1645,7 +1645,7 @@ int action_replay_load (void)
                write_log (_T("action_replay_load () ROM already loaded.\n"));
                return 0;
        }
-       if (_tcslen (currprefs.cartfile) == 0 || currprefs.cartfile[0] == ':')
+       if (currprefs.cartfile[0] == '\0' || currprefs.cartfile[0] == ':')
                return 0;
        if (currprefs.cs_cd32fmv)
                return 0;
@@ -1810,7 +1810,7 @@ int hrtmon_load (void)
        }
 
        if (!isinternal) {
-               if (_tcslen (currprefs.cartfile) == 0)
+               if (currprefs.cartfile[0] == '\0')
                        return 0;
                f = read_rom_name (currprefs.cartfile);
                if(!f) {
index 714c619dd84994a85fec58f5853f74cfd166f8dd..a1d998e98c3121b98ae73697fc887391dc32bfa8 100644 (file)
@@ -14,7 +14,7 @@ cpuop_func *loop_mode_table[65536];
 void my_trim(TCHAR *s)
 {
        int len;
-       while (_tcslen(s) > 0 && _tcscspn(s, _T("\t \r\n")) == 0)
+       while (s[0] != '\0' && _tcscspn(s, _T("\t \r\n")) == 0)
                memmove(s, s + 1, (_tcslen(s + 1) + 1) * sizeof(TCHAR));
        len = _tcslen(s);
        while (len > 0 && _tcscspn(s + len - 1, _T("\t \r\n")) == 0)
index 58204f9a33e656d21695f1432019a8bfdfb42de5..0ed9aca7d034e168192e9f4e9ccfa537ba7fd669 100644 (file)
--- a/disk.cpp
+++ b/disk.cpp
@@ -2929,7 +2929,7 @@ static void floppy_get_rootblock (uae_u8 *dst, int block, const TCHAR *disk_name
        dst[12+3] = 0x48; // size of hash table
        dst[312] = dst[313] = dst[314] = dst[315] = (uae_u8)0xff; // bitmap valid
        dst[316+2] = (block + 1) >> 8; dst[316+3] = (block + 1) & 255; // bitmap pointer
-       char *s = ua ((disk_name && _tcslen (disk_name) > 0) ? disk_name : _T("empty"));
+       char *s = ua ((disk_name && disk_name[0] != '\0') ? disk_name : _T("empty"));
        dst[432] = (uae_u8)strlen (s); // name length
        strcpy ((char*)dst + 433, s); // name
        xfree (s);
@@ -3033,7 +3033,7 @@ bool disk_creatediskfile (struct uae_prefs *p, const TCHAR *name, int type, driv
                        memcpy (dostrack, rawtrack, sizeof rawtrack);
                        dostrack[3] = 0;
                        dostrack[9] = (l * 8) >> 16; dostrack[10] = (l * 8) >> 8; dostrack[11] = (l * 8) >> 0;
-                       bool dodos = ffs || bootable || (disk_name && _tcslen (disk_name) > 0);
+                       bool dodos = ffs || bootable || (disk_name && disk_name[0] != '\0');
                        for (i = 0; i < tracks; i++) {
                                uae_u8 tmp[3 * 4];
                                memcpy (tmp, rawtrack, sizeof rawtrack);
index 8aaeed4cd9ebfd1a91b0f5080b25578ef139d821..bf0ef25852f1c6c32b5201138ee9dccc52589aa8 100644 (file)
@@ -732,7 +732,7 @@ static bool write_slot (TCHAR *p, struct uae_input_device *uid, int i, int j)
                return false;
        }
        uae_u64 flags = uid->flags[i][j];
-       if (uid->custom[i][j] && _tcslen (uid->custom[i][j]) > 0) {
+       if (uid->custom[i][j] && uid->custom[i][j][0] != '\0') {
                _stprintf (p, _T("'%s'.%d"), uid->custom[i][j], (int)(flags & ID_FLAG_SAVE_MASK_CONFIG));
                ok = true;
        } else if (uid->eventid[i][j] > 0) {
@@ -8062,7 +8062,7 @@ static int put_event_data (const struct inputdevice_functions *id, int devnum, i
                uid->flags[i][sub] = flags;
                uid->port[i][sub] = port;
                xfree (uid->custom[i][sub]);
-               uid->custom[i][sub] = custom && _tcslen (custom) > 0 ? stripstrdup (custom) : NULL;
+               uid->custom[i][sub] = custom && custom[0] != '\0' ? stripstrdup (custom) : NULL;
                ret = i;
        } else if (type == IDEV_WIDGET_AXIS) {
                i = num - id->get_widget_first (devnum, type) + ID_AXIS_OFFSET;
@@ -8070,7 +8070,7 @@ static int put_event_data (const struct inputdevice_functions *id, int devnum, i
                uid->flags[i][sub] = flags;
                uid->port[i][sub] = port;
                xfree (uid->custom[i][sub]);
-               uid->custom[i][sub] = custom && _tcslen (custom) > 0 ? stripstrdup (custom) : NULL;
+               uid->custom[i][sub] = custom && custom[0] != '\0' ? stripstrdup (custom) : NULL;
                ret = i;
        } else if (type == IDEV_WIDGET_KEY) {
                i = num - id->get_widget_first (devnum, type);
@@ -8078,7 +8078,7 @@ static int put_event_data (const struct inputdevice_functions *id, int devnum, i
                uid->flags[i][sub] = flags;
                uid->port[i][sub] = port;
                xfree (uid->custom[i][sub]);
-               uid->custom[i][sub] = custom && _tcslen (custom) > 0 ? stripstrdup (custom) : NULL;
+               uid->custom[i][sub] = custom && custom[0] != '\0' ? stripstrdup (custom) : NULL;
                ret = i;
        }
        if (ret < 0)
index b5f44bc8dbc68d269574c9729ec988851a397f57..d40bd1b9312e035ecf15893cbae8982e453d2e2e 100644 (file)
--- a/isofs.cpp
+++ b/isofs.cpp
@@ -1964,7 +1964,7 @@ root_found:
                        if (IS_ERR(inode))
                                goto out_no_root;
                        TCHAR *volname = get_joliet_name(pri->volume_id, 28, sbi->s_utf8);
-                       if (volname && _tcslen(volname) > 0) {
+                       if (volname && volname[0] != '\0') {
                                xfree(volume_name);
                                volume_name = volname;
                                write_log(_T("ISOFS: Joliet Volume ID: '%s'\n"), volume_name);
@@ -2468,7 +2468,7 @@ bool isofs_mediainfo(void *sbp, struct isofs_info *ii)
                }
                ii->unknown_media = sb->unknown_media;
                if (sb->root) {
-                       if (_tcslen(sb->root->name) == 0) {
+                       if (sb->root->name[0] == '\0') {
                                uae_tcslcpy(ii->volumename, _T("NO_LABEL"), sizeof(ii->volumename));
                        } else {
                                uae_tcslcpy (ii->volumename, sb->root->name, sizeof(ii->volumename));
index 2fec4a708922c373bbb3a97061004c77a660b936..2b463ad1185f155fc38ff9c15c37ebd091aae210 100644 (file)
@@ -1554,7 +1554,7 @@ static bool load_extendedkickstart (const TCHAR *romextfile, int type)
        int size, off;
        bool ret = false;
 
-       if (_tcslen (romextfile) == 0)
+       if (romextfile[0] == '\0')
                return false;
        if (is_arcadia_rom (romextfile) == ARCADIA_BIOS) {
                extendedkickmem_type = EXTENDED_ROM_ARCADIA;
@@ -2691,7 +2691,7 @@ static void restore_roms(void)
        load_extendedkickstart (currprefs.romextfile2, EXTENDED_ROM_CDTV);
        kickmem_bank.mask = ROM_SIZE_512 - 1;
        if (!load_kickstart ()) {
-               if (_tcslen (currprefs.romfile) > 0) {
+               if (currprefs.romfile[0] != '\0') {
                        error_log (_T("Failed to open '%s'\n"), currprefs.romfile);
                        notify_user (NUMSG_NOROM);
                }
index 903b8fdf6becdab3c241077de07fb92f1b23f5e8..8f29b3aba8c06324144d39a5be98bd30ab582a45 100644 (file)
@@ -978,7 +978,7 @@ static void update_device_info (int unitnum)
 
 static void trim (TCHAR *s)
 {
-       while (_tcslen (s) > 0 && s[_tcslen (s) - 1] == ' ')
+       while (s[0] != '\0' && s[_tcslen (s) - 1] == ' ')
                s[_tcslen (s) - 1] = 0;
 }
 
index 04142f5acbe42f8249196d605826ec6d28ad31d5..a1d10f1a7a3dc63c26980e9593e2a0942341b9da 100644 (file)
@@ -203,7 +203,7 @@ static int CheckLineLimit(HWND hWnd, const TCHAR *out)
 
        tmp = (TCHAR *)out;
        lines_have = SendMessage(hWnd, EM_GETLINECOUNT, 0, 0);
-       while (_tcslen(tmp) > 0 && (p = _tcschr(tmp, '\n'))) {
+       while (tmp[0] != '\0' && (p = _tcschr(tmp, '\n'))) {
                lines_new++;
                tmp = p + 1;
        }
@@ -245,7 +245,7 @@ void WriteOutput(const TCHAR *out, int len)
                        buf = xcalloc(TCHAR, pos + 2);
                        _tcsncpy(buf, tmp, pos - 1);
                        _tcscat(buf, linebreak);
-               } else if (_tcslen(tmp) == 0) {
+               } else if (tmp[0] == '\0') {
                        leave = 1;
                } else {
                        count = SendMessage(hOutput, EM_GETLINECOUNT, 0, 0);
@@ -1013,7 +1013,7 @@ static void ListboxEndEdit(HWND hwnd, BOOL acceptinput)
        GetWindowText(hedit, txt, MAX_LINEWIDTH + 1);
        p = txt;
        ignore_ws(&p);
-       if ((GetWindowTextLength(hedit) == 0) || (_tcslen(p) == 0))
+       if ((GetWindowTextLength(hedit) == 0) || (p[0] == '\0'))
                acceptinput = FALSE;
        while (PeekMessage(&msg, hedit, 0, 0, PM_REMOVE)) {
                TranslateMessage(&msg);
@@ -1038,7 +1038,7 @@ static void ListboxEndEdit(HWND hwnd, BOOL acceptinput)
                        double value;
                        errno = 0;
                        value = _tcstod(txt, &stopstr);
-                       if (_tcslen(stopstr) == 0 && errno == 0)
+                       if (stopstr[0] == '\0' && errno == 0)
                                regs.fp[index].fp = _tcstod(txt, &stopstr);
                }
                else {
index f6785eef2e78b620de1e2d3883fa410719e4d88d..e7518b408d022c2f4c1188d76ba9890c97be433e 100644 (file)
@@ -424,7 +424,7 @@ static int safetycheck (HANDLE h, const TCHAR *name, uae_u64 offset, uae_u8 *buf
 
 static void trim (TCHAR *s)
 {
-       while(_tcslen(s) > 0 && s[_tcslen(s) - 1] == ' ')
+       while(s[0] != '\0' && s[_tcslen(s) - 1] == ' ')
                s[_tcslen(s) - 1] = 0;
 }
 
@@ -2734,7 +2734,7 @@ static int getstorageproperty (PUCHAR outBuf, int returnedLength, struct uae_dri
                _tcscpy (udi->device_name, udi->device_path);
        }
        udi->removablemedia = devDesc->RemovableMedia;
-       while (_tcslen(udi->device_name) > 0 && udi->device_name[_tcslen(udi->device_name) - 1] == ':')
+       while (udi->device_name[0] != '\0' && udi->device_name[_tcslen(udi->device_name) - 1] == ':')
                udi->device_name[_tcslen(udi->device_name) - 1] = 0;
        for (int i = 0; i < _tcslen(udi->device_name); i++) {
                if (udi->device_name[i] == ':')
index f239109f30fa7b75e66d7870b9c724fd4d9523a6..a6ca53f50611d570f7a6b0d0dd26c2b6a71c952d 100644 (file)
@@ -563,7 +563,7 @@ static int port_insert (int inputmap_port, int devicetype, DWORD flags, const TC
        
        inputdevice_compa_clear (&changed_prefs, inputmap_port);
        
-       if (_tcslen (name) == 0) {
+       if (name[0] == '\0') {
                inputdevice_joyport_config (&changed_prefs, _T("none"), NULL, inputmap_port, 0, 0, 0, true);
                return TRUE;
        }
@@ -1638,7 +1638,7 @@ static void sendenum (void)
        cnt = 0;
        while (max--) {
                p2 = _tcschr (p1, '\n');
-               if (p2 && _tcslen (p2) > 0) {
+               if (p2 && p2[0] != '\0') {
                        TCHAR tmp2[100];
                        *p2++ = 0;
                        memset (&desc, 0, sizeof desc);
index ac5f1c854a761edd15cc09f75cb5179590573510..61d01512f0cf2456ea86400aca4950aaa455d834 100644 (file)
@@ -571,7 +571,7 @@ void write_dlog (const TCHAR *format, ...)
                _ftprintf (debugfile, _T("%s"), bufp);
        }
        lfdetected = 0;
-       if (_tcslen (bufp) > 0 && bufp[_tcslen (bufp) - 1] == '\n')
+       if (bufp[0] != '\0' && bufp[_tcslen(bufp) - 1] == '\n')
                lfdetected = 1;
        va_end (parms);
        if (bufp != buffer)
@@ -628,7 +628,7 @@ void write_logx(const TCHAR *format, ...)
                _ftprintf (debugfile, _T("%s"), bufp);
        }
        lfdetected = 0;
-       if (_tcslen (bufp) > 0 && bufp[_tcslen (bufp) - 1] == '\n')
+       if (bufp[0] != '\0' && bufp[_tcslen (bufp) - 1] == '\n')
                lfdetected = 1;
        va_end (parms);
        if (bufp != buffer)
@@ -697,7 +697,7 @@ void write_log (const TCHAR *format, ...)
 #endif
 
        lfdetected = 0;
-       if (_tcslen (bufp) > 0 && bufp[_tcslen (bufp) - 1] == '\n')
+       if (bufp[0] != '\0' && bufp[_tcslen (bufp) - 1] == '\n')
                lfdetected = 1;
        va_end (parms);
        if (bufp != buffer)
index 72c754555c7c08be72e7e3cf5122103be22e39d6..d2689cf74509a799da7de20877ac95dfef2aa1ae 100644 (file)
@@ -729,7 +729,7 @@ endofline:
                                        table68k[opc].mnemo = lookuptab[find].mnemo;
                                        break;
                                }
-                               if (_tcslen (lookuptab[find].name) == 0)
+                               if (lookuptab[find].name[0] == '\0')
                                        abort();
                        }
                }
index 6ccf82cb6960897332fbe165ea31cce52e52edb1..40f6d7b01287692439046ece81473e1eeb620a64 100644 (file)
@@ -1019,7 +1019,7 @@ void romlist_clear (void)
                                if (parent->partnumber == NULL)
                                        parent->partnumber = my_strdup (_T(""));
                                newpn = xcalloc (TCHAR, _tcslen (parent->partnumber) + 1 + _tcslen (rd->partnumber) + 1);
-                               if (_tcslen (parent->partnumber) > 0) {
+                               if (parent->partnumber[0] != '\0') {
                                        _tcscpy (newpn, parent->partnumber);
                                        _tcscat (newpn, _T("/"));
                                }
@@ -1681,7 +1681,7 @@ void getromname   (const struct romdata *rd, TCHAR *name)
                _stprintf (name + _tcslen (name), _T(" rev %d.%d"), rd->subver, rd->subrev);
        if (rd->size > 0)
                _stprintf (name + _tcslen (name), _T(" (%dk)"), (rd->size + 1023) / 1024);
-       if (rd->partnumber && _tcslen (rd->partnumber) > 0)
+       if (rd->partnumber && rd->partnumber[0] != '\0')
                _stprintf (name + _tcslen (name), _T(" [%s]"), rd->partnumber);
 }
 
@@ -1879,7 +1879,7 @@ static int read_rom_file (uae_u8 *buf, const struct romdata *rd)
        struct romlist *rl = romlist_getrl (rd);
        uae_char tmp[11];
 
-       if (!rl || _tcslen (rl->path) == 0)
+       if (!rl || rl->path[0] == '\0')
                return 0;
        zf = zfile_fopen (rl->path, _T("rb"), ZFD_NORMAL);
        if (!zf)
@@ -2582,7 +2582,7 @@ int is_device_rom(struct uae_prefs *p, int romtype, int devnum)
        struct boardromconfig *brc = get_device_rom(p, romtype, devnum, &idx);
        if (brc) {
                const TCHAR *romname = brc->roms[idx].romfile;
-               if (_tcslen(romname) == 0)
+               if (romname[0] == '\0')
                        return -1;
                if (isspecialrom(romname))
                        return 0;
index 94ca6300ee29ec33126ac8917dbfd33d5f23e587..a6af8b18fc4ebc527b1b22a6d4d493b3a5c4953c 100644 (file)
@@ -244,7 +244,7 @@ static void next_file (struct scsi_data_tape *tape)
                        return;
                }
                // LF at the end = have at least one filemark
-               if (_tcslen(name) > 0 && (name[_tcslen(name) - 1] == 10 || name[_tcslen(name) - 1] == 13)) {
+               if (name[0] != '\0' && (name[_tcslen(name) - 1] == 10 || name[_tcslen(name) - 1] == 13)) {
                        tape->last_filemark = true;
                }
                my_trim (name);