Author: rfm
Date: Tue Jul 14 20:51:30 2015
New Revision: 38793

URL: http://svn.gna.org/viewcvs/gnustep?rev=38793&view=rev
Log:
speed up logging a bit

Modified:
    libs/base/trunk/ChangeLog
    libs/base/trunk/Source/NSLog.m

Modified: libs/base/trunk/ChangeLog
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/ChangeLog?rev=38793&r1=38792&r2=38793&view=diff
==============================================================================
--- libs/base/trunk/ChangeLog   (original)
+++ libs/base/trunk/ChangeLog   Tue Jul 14 20:51:30 2015
@@ -6,6 +6,7 @@
        Stefan Bidigaray pointed out that the heading we currently write is
        very out of date.
        * Source/NSThread.m: On premature thread exist, log native thread ID.
+       * Source/NSLog.m: Optimisations to make logging a little quicker.
 
 2015-07-09  Richard Frith-Macdonald <[email protected]>
 

Modified: libs/base/trunk/Source/NSLog.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Source/NSLog.m?rev=38793&r1=38792&r2=38793&view=diff
==============================================================================
--- libs/base/trunk/Source/NSLog.m      (original)
+++ libs/base/trunk/Source/NSLog.m      Tue Jul 14 20:51:30 2015
@@ -87,6 +87,8 @@
 int _NSLogDescriptor = 2;
 
 static NSRecursiveLock *myLock = nil;
+static IMP              lockImp = 0;
+static IMP              unlockImp = 0;
 
 /**
  * Returns the lock used to protect the GNUstep NSLogv() implementation.
@@ -103,6 +105,8 @@
       if (myLock == nil)
        {
          myLock = [NSRecursiveLock new];
+          lockImp = [myLock methodForSelector: @selector(lock)];
+          unlockImp = [myLock methodForSelector: @selector(unlock)];
        }
       [gnustep_global_lock unlock];
     }
@@ -330,8 +334,8 @@
   NSMutableString      *prefix;
   NSString              *message;
   NSString              *threadName = nil;
+  NSThread              *t = nil;
   static int           pid = 0;
-  NSAutoreleasePool    *arp = [NSAutoreleasePool new];
 
   if (_NSLog_printf_handler == NULL)
     {
@@ -349,32 +353,32 @@
 
   if (GSPrivateDefaultsFlag(GSLogThread) == YES)
     {
-      NSThread  *t = GSCurrentThread();
-
+      /* If no name has been set for the current thread,
+       * we log the address of the NSThread object instead.
+       */
+      t = GSCurrentThread();
       threadName = [t name];
-      /* If no name has been set for the current thread, we log the address
-       * of the NSThread object instead.
-       */
-      if ([threadName length] == 0)
-        {
-          threadName = [NSString stringWithFormat: @"%p", t];
-        }
-    }
-
-  prefix = [NSMutableString stringWithCapacity: 1000];
+    }
+
+  prefix = [[NSMutableString alloc] initWithCapacity: 1000];
 
 #ifdef HAVE_SYSLOG
   if (GSPrivateDefaultsFlag(GSLogSyslog) == YES)
     {
-      if (nil != threadName)
+      if (nil == t)
+        {
+          [prefix appendFormat: @"[thread:%"PRIuPTR"] ",
+            GSPrivateThreadID()];
+        }
+      else if (nil == threadName)
+        {
+          [prefix appendFormat: @"[thread:%"PRIuPTR",%p] ",
+            GSPrivateThreadID(), t];
+        }
+      else
         {
           [prefix appendFormat: @"[thread:%"PRIuPTR",%@] ",
             GSPrivateThreadID(), threadName];
-        }
-      else
-        {
-          [prefix appendFormat: @"[thread:%"PRIuPTR"] ",
-            GSPrivateThreadID()];
         }
     }
   else
@@ -396,10 +400,15 @@
       [prefix appendString: cal];
       [prefix appendString: @" "];
       [prefix appendString: [[NSProcessInfo processInfo] processName]];
-      if (nil == threadName)
+      if (nil == t)
         {
           [prefix appendFormat: @"[%d:%"PRIuPTR"] ",
             pid, GSPrivateThreadID()];
+        }
+      else if (nil == threadName)
+        {
+          [prefix appendFormat: @"[%d:%"PRIuPTR",%p] ",
+            pid, GSPrivateThreadID(), t];
         }
       else
         {
@@ -416,17 +425,17 @@
       [prefix appendString: @"\n"];
     }
 
-  if (myLock == nil)
+  if (nil == myLock)
     {
       GSLogLock();
     }
 
-  [myLock lock];
+  (*lockImp)(myLock, @selector(lock));
 
   _NSLog_printf_handler(prefix);
 
-  [myLock unlock];
-
-  [arp drain];
+  (*lockImp)(myLock, @selector(unlock));
+
+  [prefix release];
 }
 


_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to