[PATCH 02/11] xkb: remove _XkbClearElems, a memset will do.

Peter Hutterer peter.hutterer at who-t.net
Thu Jan 14 21:32:10 PST 2010


Bonus point - it's easier to understand what's actually being done with the
memory.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 include/xkbsrv.h |    2 --
 xkb/XKBAlloc.c   |   13 +++++++------
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/include/xkbsrv.h b/include/xkbsrv.h
index 5d5ea9b..b1df0d3 100644
--- a/include/xkbsrv.h
+++ b/include/xkbsrv.h
@@ -299,8 +299,6 @@ extern _X_EXPORT char *	XkbBinDirectory;
 
 extern _X_EXPORT CARD32	xkbDebugFlags;
 
-#define	_XkbClearElems(a,f,l,t)	bzero(&(a)[f],((l)-(f)+1)*sizeof(t))
-
 #define	_XkbLibError(c,l,d) /* Epoch fail */
 #define	_XkbErrCode2(a,b) ((XID)((((unsigned int)(a))<<24)|((b)&0xffffff)))
 #define	_XkbErrCode3(a,b,c)	_XkbErrCode2(a,(((unsigned int)(b))<<16)|(c))
diff --git a/xkb/XKBAlloc.c b/xkb/XKBAlloc.c
index 312f54e..6464e99 100644
--- a/xkb/XKBAlloc.c
+++ b/xkb/XKBAlloc.c
@@ -36,6 +36,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include <xkbsrv.h>
 #include "xkbgeom.h"
 #include <os.h>
+#include <string.h>
 
 /***===================================================================***/
 
@@ -64,8 +65,8 @@ XkbSymInterpretRec *prev_interpret;
 	    return BadAlloc;
 	}
 	if (compat->num_si!=0) {
-	    _XkbClearElems(compat->sym_interpret,compat->num_si,
-					compat->size_si-1,XkbSymInterpretRec);
+	    memset(&compat->sym_interpret[compat->num_si], 0,
+		   (compat->size_si - compat->num_si) * sizeof(XkbSymInterpretRec));
 	}
 	return Success;
     }
@@ -159,8 +160,8 @@ XkbNamesPtr	names;
 	    names->key_aliases= xrealloc(names->key_aliases,
 					 nTotalAliases * sizeof(XkbKeyAliasRec));
 	    if (names->key_aliases!=NULL) {
-		_XkbClearElems(names->key_aliases,names->num_key_aliases,
-						nTotalAliases-1,XkbKeyAliasRec);
+		memset(&names->key_aliases[names->num_key_aliases], 0,
+			(nTotalAliases - names->num_key_aliases) * sizeof(XkbKeyAliasRec));
 	    } else {
 		xfree(prev_aliases);
 	    }
@@ -181,8 +182,8 @@ XkbNamesPtr	names;
 	    names->radio_groups= xrealloc(names->radio_groups,
 					  nTotalRG * sizeof(Atom));
 	    if (names->radio_groups!=NULL) {
-		_XkbClearElems(names->radio_groups,names->num_rg,nTotalRG-1,
-									Atom);
+		memset(&names->radio_groups[names->num_rg], 0,
+			(nTotalRG - names->num_rg) * sizeof(Atom));
 	    } else {
 		xfree(prev_radio_groups);
 	    }
-- 
1.6.6



More information about the xorg-devel mailing list