dejagnu
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

PATCH: Avoid use of [string match] to test strings for equality in runte


From: Jacob Bachmeyer
Subject: PATCH: Avoid use of [string match] to test strings for equality in runtest.exp
Date: Wed, 05 Dec 2018 19:03:53 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.22) Gecko/20090807 MultiZilla/1.8.3.4e SeaMonkey/1.1.17 Mnenhy/0.7.6.0

Older versions of Tcl may have required this use of [string match], but modern Tcl allows the much simpler "==" operator. According to time(n), "==" is also slightly faster in "if" expressions in addition to being more robust against "odd" inputs. Tidying the "if {...} {return $name}; if {...} {return $name}" is on my local TODO list along with checking for similar constructions elsewhere.

(I mention history in a "please do not blame previous contributors for this; they probably had no choice and it was good code at the time; the Tcl language has greatly improved since then" sense.)

----
ChangeLog entry:
        * runtest.exp: Fix archaic use of [string match].
----
patch:
----
diff --git a/runtest.exp b/runtest.exp
index a389c53..34e22d3 100644
--- a/runtest.exp
+++ b/runtest.exp
@@ -199,16 +199,16 @@ proc transform { name } {
    global host_triplet
    global board

-    if {[string match $target_triplet $host_triplet]} {
+    if { $target_triplet == $host_triplet } {
        return $name
    }
-    if {[string match "native" $target_triplet]} {
+    if { $target_triplet == "native" } {
        return $name
    }
    if {[board_info host exists no_transform_name]} {
        return $name
    }
-    if {[string match "" $target_triplet]} {
+    if { $target_triplet == "" } {
        return $name
    } else {
        if {[info exists board]} {
@@ -536,7 +536,7 @@ verbose "Verbose level is $verbose"
#
# get the users login name
#
-if {[string match "" $logname]} {
+if { $logname == "" } {
    if {[info exists env(USER)]} {
        set logname $env(USER)
    } else {
@@ -623,7 +623,7 @@ load_file [file join $base_dir $local_init_file]
# command line.
#

-if {[expr {[string match "." $objdir] || [string match $srcdir $objdir]}]} {
+if { $objdir == "." || $objdir == $srcdir } {
    set objdir $base_dir
} else {
    load_file [file join $objdir $local_init_file]
----


-- Jacob



reply via email to

[Prev in Thread] Current Thread [Next in Thread]