Author: rfm
Date: Sun May 24 23:22:58 2015
New Revision: 38535

URL: http://svn.gna.org/viewcvs/gnustep?rev=38535&view=rev
Log:
remove a little redundant code

Modified:
    libs/base/trunk/Source/NSZone.m

Modified: libs/base/trunk/Source/NSZone.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Source/NSZone.m?rev=38535&r1=38534&r2=38535&view=diff
==============================================================================
--- libs/base/trunk/Source/NSZone.m     (original)
+++ libs/base/trunk/Source/NSZone.m     Sun May 24 23:22:58 2015
@@ -120,10 +120,13 @@
   void *mem;
 
   mem = malloc(size);
-  if (mem == NULL)
-    [NSException raise: NSMallocException
-                 format: @"Default zone has run out of memory"];
-  return mem;
+  if (mem != NULL)
+    {
+      return mem;
+    }
+  [NSException raise: NSMallocException
+               format: @"Default zone has run out of memory"];
+  return 0;
 }
 
 static void*
@@ -131,24 +134,14 @@
 {
   void *mem;
 
-  if (size == 0)
-    {
-      free(ptr);
-      return NULL;
-    }
-  if (ptr == 0)
-    {
-      mem = malloc(size);
-      if (mem == NULL)
-       [NSException raise: NSMallocException
-                    format: @"Default zone has run out of memory"];
+  mem = realloc(ptr, size);
+  if (mem != NULL)
+    {
       return mem;
     }
-  mem = realloc(ptr, size);
-  if (mem == NULL)
-    [NSException raise: NSMallocException
-                 format: @"Default zone has run out of memory"];
-  return mem;
+  [NSException raise: NSMallocException
+               format: @"Default zone has run out of memory"];
+  return 0;
 }
 
 static void
@@ -271,7 +264,7 @@
   return &default_zone;
 }
 
-NSZone*
+inline NSZone*
 NSDefaultMallocZone (void)
 {
   return &default_zone;
@@ -443,7 +436,7 @@
   return &default_zone;
 }
 
-NSZone*
+inline NSZone*
 NSDefaultMallocZone (void)
 {
   return &default_zone;
@@ -2072,6 +2065,18 @@
 void*
 NSZoneCalloc (NSZone *zone, NSUInteger elems, NSUInteger bytes)
 {
+  void *mem;
+
+  if (0 == zone || NSDefaultMallocZone() == zone)
+    {
+      mem = calloc(elems, bytes);
+      if (mem != NULL)
+        {
+          return mem;
+        }
+      [NSException raise: NSMallocException
+                  format: @"Default zone has run out of memory"];
+    }
   return memset(NSZoneMalloc(zone, elems*bytes), 0, elems*bytes);
 }
 


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

Reply via email to