Sujet : Re: OK, what looks better. The OLD tcl-oo or the NEW tcl-oo?
De : aotto1968 (at) *nospam* t-online.de (aotto1968)
Groupes : comp.lang.tclDate : 28. Jan 2025, 23:00:51
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vnbk2j$20pk0$1@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
I'm still struggling with myself as to whether "myoo" should be reference-based or namespace-based.
after doing some research with the tcl-only API, I've now switched to C. Unfortunately, the public namespace C API is rather weak and only "string" based, which has now prompted me to switch to the semi-public "Int" API, where at least there is usable "namespace" support. After the first analysis, I can now say that "namespace-based" is currently faster.
package require libmyoox
> 1.0
::myooX::ClassN ::MyClassN {
proc MyClassN {myNs num} {
namespace upvar $myNs my my
set my(num) $num
}
proc get {myNs} {
namespace upvar $myNs my my
set my(num)
}
}
> ::MyClassN::cls
::myooX::ClassN ::MyClassR {
proc MyClassR {myRef num} {
upvar $myRef my
set my(num) $num
}
proc get {myRef} {
upvar $myRef my
set my(num)
}
}
> ::MyClassR::cls
set ns1 [::myooX::NewN ::MyClassN 1]
> ::MyClassN::MyClassN-1
set ref2 [::myooX::NewR ::MyClassR::cls 2]
> ::MyClassR::MyClassR-1::my
::MyClassN::get $ns1
> 1
::MyClassR::get $ref2
> 2
time {::myooX::NewN ::MyClassN 1 } 10000
> 10.244 microseconds per iteration
time {::myooX::NewR ::MyClassR::cls 2 } 10000
> 15.086 microseconds per iteration
time {::MyClassN::get $ns1 } 10000
> 1.6015 microseconds per iteration
time {::MyClassR::get $ref2 } 10000
> 2.4201 microseconds per iteration