From 62890f6ecc29d0d8f69d5ba9f02124c38c10cad5 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Wed, 14 Oct 2015 04:06:26 +0200 Subject: [PATCH] Reduce the number of getParent() function calls for print operations --- ChangeLog | 3 +++ build.sh | 26 ++++++++++++++++++++------ scripts/cpuprofile.sh | 4 ++-- scripts/kcachegrind.sh | 6 ++++++ scripts/library_calls.sh | 4 ++-- scripts/profile.sh | 9 ++++----- src/fterm.cpp | 16 ++++++---------- src/fwidget.cpp | 33 +++++++++++++++++++++++++++++++++ src/fwidget.h | 4 ++++ 9 files changed, 80 insertions(+), 25 deletions(-) create mode 100755 scripts/kcachegrind.sh diff --git a/ChangeLog b/ChangeLog index ccdc00d6..c42c0680 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2015-10-13 Markus Gans + * Reduce the number of getParent() function calls for print operations + 2015-10-11 Markus Gans * Improve attribute setting for bold, reverse and underline output * Better support for monochrom terminals diff --git a/build.sh b/build.sh index 4afa2088..562d7c65 100755 --- a/build.sh +++ b/build.sh @@ -4,25 +4,39 @@ PREFIX="/usr" case "$1" in - "--help"|"help") - echo "Usage: $0 {help|debug|fulldebug|profile|gcov|release}" - exit 1 - ;; "--debug"|"debug") ./configure --prefix="$PREFIX" CPPFLAGS="-DDEBUG" CXXFLAGS="-g -O0 -DDEBUG -W -Wall -pedantic" ;; + "--fulldebug"|"fulldebug") ./configure --prefix="$PREFIX" CPPFLAGS="-DDEBUG" CXXFLAGS="-g -O0 -DDEBUG -W -Wall -Weffc++ -pedantic -pedantic-errors -Wextra -Wformat-nonliteral -Wformat-security -Wformat-y2k -Wimport -Winit-self -Winvalid-pch -Wlong-long -Wmissing-braces -Wmissing-field-initializers -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn -Wpacked -Wpadded -Wparentheses -Wpointer-arith -Wredundant-decls -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wstack-protector -Wstrict-aliasing -Wstrict-aliasing=2 -Wswitch -Wswitch-enum -Wtrigraphs -Wuninitialized -Wunknown-pragmas -Wunreachable-code -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value -Wunused-variable -Wvariadic-macros -Wvolatile-register-var -Wwrite-strings -Wsign-promo -Woverloaded-virtual -Wstrict-null-sentinel -fext-numeric-literals -Wreorder -Wnoexcept -Wnarrowing -Wliteral-suffix -Wctor-dtor-privacy" ;; + "--profile"|"profile") - ./configure --prefix="$PREFIX" CPPFLAGS="-DDEBUG" CXXFLAGS="-pg -O0 -DDEBUG -W -Wall -pedantic" + ./configure --prefix="$PREFIX" CPPFLAGS="-DDEBUG" CXXFLAGS="-g -pg -O0 -DDEBUG -W -Wall -pedantic" ;; + "--gcov"|"gcov") ./configure --prefix="$PREFIX" CXXFLAGS="-fprofile-arcs -ftest-coverage" ;; - "--release"|"release"|*) + + "--release"|"release") ./configure --prefix="$PREFIX" ;; + + "--help"|"help"|*) + echo "Usage:" + echo " $(basename "$0") {COMMAND}" + echo "" + echo "Commands:" + echo " help Show this help" + echo " debug Compile with debug option" + echo " fulldebug Compile with all warning options" + echo " profile Compile with profile option (analysis with gprof)" + echo " gcov Compile with options for coverage analysis with gcov" + echo " release Compile for release" + exit 1 + ;; esac make V=1 -j10 diff --git a/scripts/cpuprofile.sh b/scripts/cpuprofile.sh index 9557adb5..3f407ffc 100755 --- a/scripts/cpuprofile.sh +++ b/scripts/cpuprofile.sh @@ -1,5 +1,5 @@ #!/bin/bash -LD_PRELOAD="/usr/lib64/libprofiler.so.0" CPUPROFILE=../text/ui.prof ../test/ui -pprof --gv ../test/ui ../test/ui.prof +LD_LIBRARY_PATH=../src/.libs/ LD_PRELOAD="/usr/lib64/libprofiler.so.0" CPUPROFILE=../test/.libs/ui.prof ../test/.libs/ui +pprof --gv ../test/.libs/ui ../test/.libs/ui.prof diff --git a/scripts/kcachegrind.sh b/scripts/kcachegrind.sh new file mode 100755 index 00000000..8074b053 --- /dev/null +++ b/scripts/kcachegrind.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +LD_LIBRARY_PATH=../src/.libs/ valgrind --tool=callgrind -v ../test/.libs/ui 2>/dev/null +kcachegrind +rm -f callgrind.out.* + diff --git a/scripts/library_calls.sh b/scripts/library_calls.sh index e8d17c4c..5cc384d9 100755 --- a/scripts/library_calls.sh +++ b/scripts/library_calls.sh @@ -4,7 +4,7 @@ PROG="ui" -ltrace -o ./$PROG.ltrace ../test/.libs/$PROG +LD_LIBRARY_PATH=../src/.libs/ ltrace -o ./$PROG.ltrace ../test/.libs/$PROG less ./$PROG.ltrace -rm -f ./$PROG.ltrace +rm -f ./$PROG.ltrace ./gmon.out diff --git a/scripts/profile.sh b/scripts/profile.sh index a6511725..036fcf3b 100755 --- a/scripts/profile.sh +++ b/scripts/profile.sh @@ -1,12 +1,11 @@ #!/bin/bash DIR="$PWD" -cd ../src -make clean -make profile -./finalcut -gprof ./finalcut >./profile.txt +cd ../test/.libs/ +LD_LIBRARY_PATH=../../src/.libs/ ./ui +gprof ./ui >./profile.txt rm ./gmon.out less ./profile.txt rm ./profile.txt cd "$DIR" + diff --git a/src/fterm.cpp b/src/fterm.cpp index e9a866d8..28d78d12 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -3804,14 +3804,12 @@ int FTerm::print (FString& s) term_area* area; FWidget* w; w = static_cast(this); - FWidget* area_widget = FWindow::getWindowWidget(w); + area = w->getPrintArea(); - if ( area_widget && area_widget->getVWin() ) - area = area_widget->getVWin(); - else + if ( ! area ) { + FWidget* area_widget = w->getRootWidget(); area = vdesktop; - area_widget = w->getRootWidget(); if ( ! area_widget ) return -1; } @@ -3934,14 +3932,12 @@ int FTerm::print (register int c) term_area* area; FWidget* w; w = static_cast(this); - FWidget* area_widget = FWindow::getWindowWidget(w); + area = w->getPrintArea(); - if ( area_widget ) - area = area_widget->getVWin(); - else + if ( ! area ) { + FWidget* area_widget = w->getRootWidget(); area = vdesktop; - area_widget = w->getRootWidget(); if ( ! area_widget ) return -1; } diff --git a/src/fwidget.cpp b/src/fwidget.cpp index b7a3f4a2..2b7c1d58 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -68,6 +68,7 @@ FWidget::FWidget (FWidget* parent) , adjustWidgetSize(1,1,1,1) , adjustWidgetSizeGlobal(1,1,1,1) , statusbar_message() + , print_area(0) { resize_term = false; @@ -359,6 +360,38 @@ void FWidget::setColorTheme() } } +//---------------------------------------------------------------------- +FTerm::term_area* FWidget::getPrintArea() +{ + if ( print_area ) + return print_area; + else + { + FWidget* area_widget = FWindow::getWindowWidget(this); + + if ( area_widget ) + { + term_area* area = area_widget->getVWin(); + + if ( area ) + { + print_area = area; + return area; + } + else + return 0; + } + else + return 0; + } +} + +//---------------------------------------------------------------------- +void FWidget::setPrintArea(term_area* area) +{ + print_area = area; +} + // protected methods of FWidget //---------------------------------------------------------------------- void FWidget::adjustSize() diff --git a/src/fwidget.h b/src/fwidget.h index ae6f636b..5e8485aa 100644 --- a/src/fwidget.h +++ b/src/fwidget.h @@ -277,6 +277,8 @@ class FWidget : public FObject, public FTerm static FMenuBar* menubar; static FWidget* show_root_widget; static FWidget* redraw_root_widget; + term_area* print_area; + friend class FTerm; friend class FApplication; friend class FToggleButton; @@ -288,6 +290,8 @@ class FWidget : public FObject, public FTerm void processDestroy(); virtual void draw(); static void setColorTheme(); + term_area* getPrintArea(); + void setPrintArea(term_area*); protected: virtual void adjustSize();