From f9c014d008e42eab79cffd6441147cbc95963cf5 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 18 Jul 2012 07:44:17 +0000 Subject: [PATCH] empty_p: optimize and warnings * ext/dbm/dbm.c (fdbm_empty_p): not empty if first key exists. suppress warnngs by gcc 4.7 -Wstrict-overflow. * ext/sdbm/init.c (fsdbm_empty_p): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36438 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/dbm/dbm.c | 9 ++++----- ext/sdbm/init.c | 9 ++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/ext/dbm/dbm.c b/ext/dbm/dbm.c index 4bc1ce3e40..8f50e32192 100644 --- a/ext/dbm/dbm.c +++ b/ext/dbm/dbm.c @@ -689,21 +689,20 @@ fdbm_empty_p(VALUE obj) datum key; struct dbmdata *dbmp; DBM *dbm; - int i = 0; GetDBM2(obj, dbmp, dbm); if (dbmp->di_size < 0) { dbm = dbmp->di_dbm; for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) { - i++; + return Qfalse; } } else { - i = (int)dbmp->di_size; + if (!dbmp->di_size) + return Qfalse; } - if (i == 0) return Qtrue; - return Qfalse; + return Qtrue; } /* diff --git a/ext/sdbm/init.c b/ext/sdbm/init.c index 65e2ded07b..1795024ff9 100644 --- a/ext/sdbm/init.c +++ b/ext/sdbm/init.c @@ -714,21 +714,20 @@ fsdbm_empty_p(VALUE obj) datum key; struct dbmdata *dbmp; DBM *dbm; - int i = 0; GetDBM(obj, dbmp); if (dbmp->di_size < 0) { dbm = dbmp->di_dbm; for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) { - i++; + return Qfalse; } } else { - i = dbmp->di_size; + if (!dbmp->di_size) + return Qfalse; } - if (i == 0) return Qtrue; - return Qfalse; + return Qtrue; } /*