PATCH: Avoid use of [string match] to test strings for equality in runtest.exp

Jacob Bachmeyer <[email protected]>
Newsgroups gmane.comp.sysutils.dejagnu.general
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.