[PATCH 09/11] Reduce unnecessary string copying in xkbtext routines

Alan Coopersmith alan.coopersmith at oracle.com
Thu Nov 3 22:34:18 PDT 2011


Instead of using sprintf to copy a static string to a local buffer,
just to pass it to TryCopyStr, pass the static string to TryCopyStr
directly, as is already done in other parts of this code.

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---

As pointed out by walter, we don't need sprintf to format a constant
string, and since we're not formatting it, there's no need to write
a copy to local buffer before passing to TryCopyStr.

 xkb/xkbtext.c |   18 ++++++++----------
 1 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/xkb/xkbtext.c b/xkb/xkbtext.c
index f7502f6..8ef2b05 100644
--- a/xkb/xkbtext.c
+++ b/xkb/xkbtext.c
@@ -772,15 +772,14 @@ char			tbuf[32];
     if (action->type==XkbSA_LockPtrBtn) {
 	switch (act->flags&(XkbSA_LockNoUnlock|XkbSA_LockNoLock)) {
 	    case XkbSA_LockNoLock:
-		sprintf(tbuf,",affect=unlock"); break;
+		TryCopyStr(buf,",affect=unlock",sz); break;
 	    case XkbSA_LockNoUnlock:
-		sprintf(tbuf,",affect=lock"); break;
+		TryCopyStr(buf,",affect=lock",sz); break;
 	    case XkbSA_LockNoUnlock|XkbSA_LockNoLock:
-		sprintf(tbuf,",affect=neither"); break;
+		TryCopyStr(buf,",affect=neither",sz); break;
 	    default:
-		sprintf(tbuf,",affect=both"); break;
+		TryCopyStr(buf,",affect=both",sz); break;
 	}
-	TryCopyStr(buf,tbuf,sz);
     }
     return TRUE;
 }
@@ -1065,15 +1064,14 @@ char			tbuf[32];
     if (action->type==XkbSA_LockDeviceBtn) {
 	switch (act->flags&(XkbSA_LockNoUnlock|XkbSA_LockNoLock)) {
 	    case XkbSA_LockNoLock:
-		sprintf(tbuf,",affect=unlock"); break;
+		TryCopyStr(buf,",affect=unlock",sz); break;
 	    case XkbSA_LockNoUnlock:
-		sprintf(tbuf,",affect=lock"); break;
+		TryCopyStr(buf,",affect=lock",sz); break;
 	    case XkbSA_LockNoUnlock|XkbSA_LockNoLock:
-		sprintf(tbuf,",affect=neither"); break;
+		TryCopyStr(buf,",affect=neither",sz); break;
 	    default:
-		sprintf(tbuf,",affect=both"); break;
+		TryCopyStr(buf,",affect=both",sz); break;
 	}
-	TryCopyStr(buf,tbuf,sz);
     }
     return TRUE;
 }
-- 
1.7.3.2



More information about the xorg-devel mailing list