Bwidget Source Code
View Ticket
Not logged in
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.
Ticket UUID: 7909befc6ad28c02369fbfd77a8424ab89054321
Title: Unnecessary temporary widget creation
Type: Patch Version: 1.9.7
Submitter: anonymous Created on: 2014-05-14 09:53:32
Subsystem: (unused) Assigned To: nobody
Priority: 5 Medium Severity: Minor
Status: Deleted Last Modified: 2014-05-19 13:06:34
Resolution: Duplicate Closed By: oehhar
    Closed on: 2014-05-19 13:06:34
Description:
From: Adrián Medraño Calvo <[email protected]>

Not long ago, my colleage Wolfgang S. Kechel sent a patch removing unneeded
creation of ".ericFoo##" widget. This continues the job by removing another
instance of the issue.

The temporary widget was being created with the purpose of retrieving the
default values, but this functionality is already encapsulated by the
[_get_tkwidget_options] procedure. As such, there is no need to create an
additional temporary widget. As the code was already invoking
[_get_tkwidget_options], its result is simply reused.
---
 bwidget-1.9.7/widget.tcl | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/bwidget-1.9.7/widget.tcl b/bwidget-1.9.7/widget.tcl
index 98c6852..d4748f3 100755
--- a/bwidget-1.9.7/widget.tcl
+++ b/bwidget-1.9.7/widget.tcl
@@ -372,24 +372,24 @@ proc Widget::declare { class optlist } {
         # retreive default value for TkResource
         if { [string equal $type "TkResource"] } {
             set tkwidget [lindex $arg 0]
-	    set foo [$tkwidget ".ericFoo##"]
             set realopt  [lindex $arg 1]
             if { ![string length $realopt] } {
                 set realopt $option
             }
             set tkoptions [_get_tkwidget_options $tkwidget]
+            set ind [lsearch $tkoptions [list $realopt *]]
+            set optdesc [lindex $tkoptions $ind];
             if { ![string length $value] } {
                 # We initialize default value
-		set ind [lsearch $tkoptions [list $realopt *]]
-                set value [lindex [lindex $tkoptions $ind] end]
+                set value [lindex $optdesc end]
             }
 	    set optionDbName ".[lindex [_configure_option $option ""] 0]"
 	    option add *${class}${optionDbName} $value widgetDefault
 	    set exports($option) $optionDbName
             set classopt($option) [list TkResource $value $ro \
 		    [list $tkwidget $realopt]]
-	    set optionClass($option) [lindex [$foo configure $realopt] 1]
-	    ::destroy $foo
+	    set optionClass($option) [lindex $optdesc 1]
+
             continue
         }
 
-- 
1.9.2