[前][次][番号順一覧][スレッド一覧]

ruby-changes:48241

From: rhe <ko1@a...>
Date: Sun, 22 Oct 2017 16:18:59 +0900 (JST)
Subject: [ruby-changes:48241] rhe:r60356 (trunk): gdbm, dbm, sdbm: remove unnecessary conditions

rhe	2017-10-22 16:18:55 +0900 (Sun, 22 Oct 2017)

  New Revision: 60356

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60356

  Log:
    gdbm, dbm, sdbm: remove unnecessary conditions
    
    The dfree and dsize callback functions are never called with NULL.

  Modified files:
    trunk/ext/dbm/dbm.c
    trunk/ext/gdbm/gdbm.c
    trunk/ext/sdbm/init.c
Index: ext/dbm/dbm.c
===================================================================
--- ext/dbm/dbm.c	(revision 60355)
+++ ext/dbm/dbm.c	(revision 60356)
@@ -59,21 +59,18 @@ static void https://github.com/ruby/ruby/blob/trunk/ext/dbm/dbm.c#L59
 free_dbm(void *ptr)
 {
     struct dbmdata *dbmp = ptr;
-    if (dbmp) {
-	if (dbmp->di_dbm) dbm_close(dbmp->di_dbm);
-	xfree(dbmp);
-    }
+    if (dbmp->di_dbm)
+	dbm_close(dbmp->di_dbm);
+    xfree(dbmp);
 }
 
 static size_t
 memsize_dbm(const void *ptr)
 {
-    size_t size = 0;
     const struct dbmdata *dbmp = ptr;
-    if (dbmp) {
-	size += sizeof(*dbmp);
-	if (dbmp->di_dbm) size += DBM_SIZEOF_DBM;
-    }
+    size_t size = sizeof(*dbmp);
+    if (dbmp->di_dbm)
+	size += DBM_SIZEOF_DBM;
     return size;
 }
 
Index: ext/gdbm/gdbm.c
===================================================================
--- ext/gdbm/gdbm.c	(revision 60355)
+++ ext/gdbm/gdbm.c	(revision 60356)
@@ -114,21 +114,18 @@ static void https://github.com/ruby/ruby/blob/trunk/ext/gdbm/gdbm.c#L114
 free_dbm(void *ptr)
 {
     struct dbmdata *dbmp = ptr;
-    if (dbmp) {
-        if (dbmp->di_dbm) gdbm_close(dbmp->di_dbm);
-        xfree(dbmp);
-    }
+    if (dbmp->di_dbm)
+	gdbm_close(dbmp->di_dbm);
+    xfree(dbmp);
 }
 
 static size_t
 memsize_dbm(const void *ptr)
 {
-    size_t size = 0;
     const struct dbmdata *dbmp = ptr;
-    if (dbmp) {
-	size += sizeof(*dbmp);
-	if (dbmp->di_dbm) size += DBM_SIZEOF_DBM;
-    }
+    size_t size = sizeof(*dbmp);
+    if (dbmp->di_dbm)
+	size += DBM_SIZEOF_DBM;
     return size;
 }
 
Index: ext/sdbm/init.c
===================================================================
--- ext/sdbm/init.c	(revision 60355)
+++ ext/sdbm/init.c	(revision 60356)
@@ -99,12 +99,10 @@ free_sdbm(void *ptr) https://github.com/ruby/ruby/blob/trunk/ext/sdbm/init.c#L99
 static size_t
 memsize_dbm(const void *ptr)
 {
-    size_t size = 0;
     const struct dbmdata *dbmp = ptr;
-    if (dbmp) {
-	size += sizeof(*dbmp);
-	if (dbmp->di_dbm) size += sizeof(DBM);
-    }
+    size_t size = sizeof(*dbmp);
+    if (dbmp->di_dbm)
+	size += sizeof(DBM);
     return size;
 }
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]