[gnome-music/gnome-3-16] Reduce the overhead of the @log decorator



commit 1e67be91d724e2fe8a072854f7dffea0a7d43471
Author: Mathieu Bridon <bochecha daitauha fr>
Date:   Tue Jun 9 18:16:35 2015 +0200

    Reduce the overhead of the @log decorator
    
    With this, if the log level is set to anything else than logging.DEBUG,
    the decorator does absolutely nothing, it just returns the decorated
    function unmodified.
    
    Given how often this decorator is used, this could improve performance
    a bit, avoiding to compute the artefacts used in the debug log message
    if they are not going to be outputted anyway.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=750686

 gnome-music.in         |    4 ++--
 gnomemusic/__init__.py |    4 +++-
 2 files changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/gnome-music.in b/gnome-music.in
index 3bade7c..59da73b 100644
--- a/gnome-music.in
+++ b/gnome-music.in
@@ -35,8 +35,6 @@ from gi.repository import GIRepository
 GIRepository.Repository.prepend_search_path(libgd_typelibdir)
 GIRepository.Repository.prepend_library_path(libgd_libdir)
 
-from gnomemusic.application import Application
-
 
 def install_excepthook():
     """ Make sure we exit when an unhandled exception occurs. """
@@ -78,6 +76,8 @@ if __name__ == "__main__":
     resource = Gio.resource_load(os.path.join(pkgdatadir, 'gnome-music.gresource'))
     Gio.Resource._register(resource)
 
+    from gnomemusic.application import Application
+
     app = Application()
     signal.signal(signal.SIGINT, signal.SIG_DFL)
     exit_status = app.run(sys.argv)
diff --git a/gnomemusic/__init__.py b/gnomemusic/__init__.py
index 9666dd7..a69b937 100644
--- a/gnomemusic/__init__.py
+++ b/gnomemusic/__init__.py
@@ -26,13 +26,15 @@
 # delete this exception statement from your version.
 
 from gi.repository import Tracker
+from itertools import chain
 import logging
 logger = logging.getLogger(__name__)
 tabbing = 0
 
 
 def log(fn):
-    from itertools import chain
+    if logger.getEffectiveLevel() > logging.DEBUG:
+        return fn
 
     def wrapped(*v, **k):
         global tabbing


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