DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

Link: http://www.fltk.org/str.php?L2708
Version: 1.3-feature


While working on the patch for STR #2706 I decided to look into some more
fluid issues that have been bugging me for a while. Here is #2:

Fluid implements all class member widget callbacks as two nested function
calls. (I say "class member", because this is not true for simple cases
when a Fluid GUI is implemented in a global function. Then all callbacks
are just static functions in the C++ file.) The "outer" function is a
static and private class member, needs to be this way to be usable as a
widget callback. The inner function is private and is invoked via a class
instance "this" pointer by the "outer" function. It needs to be this way
so that the user provided callback code snippet can be copied unchanged
into the body of this inner function. I.e.:

class SomeUserInterface {
  ...
  static void cb_somewidget(Fl_SomeWidget*, void*);  // calls
"cb_somewidget_i" via a "this" pointer derived from the widget argument
  void cb_somewidget_i(Fl_SomeWidget*, void*);  // user code copied into
its body
  ...
}; 

I propose to change to fluid code generator output to this (change is only
needed in the header file):

class SomeUserInterface {
  ...
  static void cb_somewidget(Fl_SomeWidget*, void*);  
  inline void cb_somewidget_i(Fl_SomeWidget*, void*);
  ...
}; 

Again, remember that the "_i" member is private, is only called from a
single place, is always in the same C++ source file as its caller and is
typically short. In fact, based on my looking at some compiled code, "g++
-O2" will already inline the "_i" function in most cases, but then -- not
knowing any better -- will output an unnecessary copy of it too. 

Here are the results of building a real life application (some fluid, some
other code) from the exact same sources with the only difference being that
the .fl files were translated with the "before" and "after" versions of
fluid:

   text    data     bss     dec     hex filename
3136623  176332  423120 3736075  39020b bin/Release/Linux/i686/ds-old
3102006  176340  423120 3701466  387ada bin/Release/Linux/i686/ds

And some of the bigger fluid objects:
   text    data     bss     dec     hex filename
  52371   48512     936  101819   18dbb mainwindow.o
 109053    8360     184  117597   1cb5d setuppanel.o
  44755   48512     936   94203   16ffb mainwindow.o
 100653    8360     184  109197   1aa8d setuppanel.o

Patch attached.


Link: http://www.fltk.org/str.php?L2708
Version: 1.3-feature
diff -ur fltk-1.3.x-r8914-orig//fluid/Fl_Menu_Type.cxx 
fltk-1.3.x-r8914//fluid/Fl_Menu_Type.cxx
--- fltk-1.3.x-r8914-orig//fluid/Fl_Menu_Type.cxx       2011-08-25 
16:41:24.000000000 -0500
+++ fltk-1.3.x-r8914//fluid/Fl_Menu_Type.cxx    2011-08-26 17:51:34.000000000 
-0500
@@ -353,7 +353,7 @@
       const char* cn = callback_name();
       const char* ut = user_data_type() ? user_data_type() : "void*";
       write_public(0);
-      write_h("  void %s_i(Fl_Menu_*, %s);\n", cn, ut);
+      write_h("  inline void %s_i(Fl_Menu_*, %s);\n", cn, ut);
       write_h("  static void %s(Fl_Menu_*, %s);\n", cn, ut);
     }
   }
diff -ur fltk-1.3.x-r8914-orig//fluid/Fl_Widget_Type.cxx 
fltk-1.3.x-r8914//fluid/Fl_Widget_Type.cxx
--- fltk-1.3.x-r8914-orig//fluid/Fl_Widget_Type.cxx     2011-08-07 
09:58:41.000000000 -0500
+++ fltk-1.3.x-r8914//fluid/Fl_Widget_Type.cxx  2011-08-26 17:51:34.000000000 
-0500
@@ -2081,7 +2081,7 @@
     const char* cn = callback_name();
     const char* ut = user_data_type() ? user_data_type() : "void*";
     write_public(0);
-    write_h("  void %s_i(%s*, %s);\n", cn, t, ut);
+    write_h("  inline void %s_i(%s*, %s);\n", cn, t, ut);
     write_h("  static void %s(%s*, %s);\n", cn, t, ut);
   }
   // figure out if local variable will be used (prevent compiler warnings):
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to