From 2b3568bddcade8349e0d08a6bb7c1dc9e1cd2e9c Mon Sep 17 00:00:00 2001 From: lainon Date: Wed, 21 Sep 2022 15:41:18 +0300 Subject: [PATCH] Optimize compiler code generation for 'strlen()' --- ar.cpp | 4 ++-- cputest_support.cpp | 2 +- disk.cpp | 4 ++-- inputdevice.cpp | 8 ++++---- isofs.cpp | 4 ++-- memory.cpp | 4 ++-- od-win32/blkdev_win32_ioctl.cpp | 2 +- od-win32/debug_win32.cpp | 8 ++++---- od-win32/hardfile_win32.cpp | 4 ++-- od-win32/rp.cpp | 4 ++-- od-win32/writelog.cpp | 6 +++--- readcpu.cpp | 2 +- rommgr.cpp | 8 ++++---- scsitape.cpp | 2 +- 14 files changed, 31 insertions(+), 31 deletions(-) diff --git a/ar.cpp b/ar.cpp index 0846d501..50e48469 100644 --- 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) { diff --git a/cputest_support.cpp b/cputest_support.cpp index 714c619d..a1d998e9 100644 --- a/cputest_support.cpp +++ b/cputest_support.cpp @@ -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) diff --git a/disk.cpp b/disk.cpp index 58204f9a..0ed9aca7 100644 --- 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); diff --git a/inputdevice.cpp b/inputdevice.cpp index 8aaeed4c..bf0ef258 100644 --- a/inputdevice.cpp +++ b/inputdevice.cpp @@ -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) diff --git a/isofs.cpp b/isofs.cpp index b5f44bc8..d40bd1b9 100644 --- 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)); diff --git a/memory.cpp b/memory.cpp index 2fec4a70..2b463ad1 100644 --- a/memory.cpp +++ b/memory.cpp @@ -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); } diff --git a/od-win32/blkdev_win32_ioctl.cpp b/od-win32/blkdev_win32_ioctl.cpp index 903b8fdf..8f29b3ab 100644 --- a/od-win32/blkdev_win32_ioctl.cpp +++ b/od-win32/blkdev_win32_ioctl.cpp @@ -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; } diff --git a/od-win32/debug_win32.cpp b/od-win32/debug_win32.cpp index 04142f5a..a1d10f1a 100644 --- a/od-win32/debug_win32.cpp +++ b/od-win32/debug_win32.cpp @@ -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 { diff --git a/od-win32/hardfile_win32.cpp b/od-win32/hardfile_win32.cpp index f6785eef..e7518b40 100644 --- a/od-win32/hardfile_win32.cpp +++ b/od-win32/hardfile_win32.cpp @@ -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] == ':') diff --git a/od-win32/rp.cpp b/od-win32/rp.cpp index f239109f..a6ca53f5 100644 --- a/od-win32/rp.cpp +++ b/od-win32/rp.cpp @@ -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); diff --git a/od-win32/writelog.cpp b/od-win32/writelog.cpp index ac5f1c85..61d01512 100644 --- a/od-win32/writelog.cpp +++ b/od-win32/writelog.cpp @@ -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) diff --git a/readcpu.cpp b/readcpu.cpp index 72c75455..d2689cf7 100644 --- a/readcpu.cpp +++ b/readcpu.cpp @@ -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(); } } diff --git a/rommgr.cpp b/rommgr.cpp index 6ccf82cb..40f6d7b0 100644 --- a/rommgr.cpp +++ b/rommgr.cpp @@ -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; diff --git a/scsitape.cpp b/scsitape.cpp index 94ca6300..a6af8b18 100644 --- a/scsitape.cpp +++ b/scsitape.cpp @@ -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); -- 2.47.3