Two small GtkItemFactory glitches



Aloha,

while finally doing some Perl again for the first time in weeks, I found
two small problems with Gtk2::ItemFactory:

* Gtk2::ItemFactory::new already takes a GtkAccelGroup_ornull but lacks
a =NULL to actually be able to say

  Gtk2::ItemFactory -> new("Gtk2::WhatEver", "<main>");

and get an AccelGroup created for you.  Patch attached.

* Gtk2::ItemFactory::create_item strips off underscores from the path to
get a clean path that is then used to access the menu widget associated
with the path.  The current implementation doesn't work if the path
contains more than one consecutive underscores, though.  You do that to
get normal underscores in the menu.  To get the string that is used to
identify the widget GTK+ replaces any number of consecutive underscores
with just one in those cases.

Attached are three patches that all do exactly that in the Perl
implementation.  Christian (Borup) and I turned the search for a regular
expression that does the job into a contest - the results are attached.

The most elegant one (borup_v2) unfortunately is also the slowest,
whereas the fastest one requires changes to the cool "entirely for this
line right here".

-----------------------------------------------------------------------
# perl -MBenchmark -wle'timethese(1_000_000, { torsten => sub { $_ =
"bla ______ bla"; s/_(_)*/defined($1) ? "_" : ""/ge; }, borup => sub {
$_ = "bla ______ bla"; s/_(?!_+)//; s/_+/_/; }, borup_v2 => sub { $_ =
"bla ______ bla"; s/_(_?)_*/$1/g; } });'
Benchmark:
timing 1000000 iterations of
 borup, borup_v2, torsten
...
                                                                                
     borup:  4 wallclock secs ( 4.54 usr +  0.01 sys =  4.55 CPU) @
219780.22/s (n=1000000)
                                                                                
  borup_v2:  8 wallclock secs ( 6.48 usr +  0.01 sys =  6.49 CPU) @
154083.20/s (n=1000000)
                                                                                
   torsten:  7 wallclock secs ( 6.15 usr +  0.02 sys =  6.17 CPU) @
162074.55/s (n=1000000)

-----------------------------------------------------------------------

Choice is yours!

Bye,
-Torsten

P.S: It should be noted that the orignal challenge was to find *a* (as
in "one") regular expression that solves this problem - so Christian
effectively cheated in the "borup" version.

Attachment: gtk2perl_gtk_item_factory_new.patch
Description: Text Data

Attachment: gtk2perl_gtk_item_factory_create_item_regexp_borup.patch
Description: Text Data

Attachment: gtk2perl_gtk_item_factory_create_item_regexp_borup_v2.patch
Description: Text Data

Attachment: gtk2perl_gtk_item_factory_create_item_regexp_torsten.patch
Description: Text Data



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