linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drivers/video/fbdev/sis/sis_main.c: avoid repeated strlen() calls
@ 2015-06-09 13:04 Rasmus Villemoes
  2015-06-12  9:36 ` Tomi Valkeinen
  0 siblings, 1 reply; 2+ messages in thread
From: Rasmus Villemoes @ 2015-06-09 13:04 UTC (permalink / raw)
  To: Thomas Winischhofer, Jean-Christophe Plagniol-Villard, Tomi Valkeinen
  Cc: Rasmus Villemoes, linux-fbdev, linux-kernel

gcc is not smart enough to realize that strlen(strbuf1) cannot be
changed by the loop body, so it is forced to recompute it, at least in
the branch containing the assignment. Avoid this by using an
equivalent stopping condition.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 drivers/video/fbdev/sis/sis_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/sis/sis_main.c b/drivers/video/fbdev/sis/sis_main.c
index fcf610edf217..ea95f8bf3922 100644
--- a/drivers/video/fbdev/sis/sis_main.c
+++ b/drivers/video/fbdev/sis/sis_main.c
@@ -172,7 +172,7 @@ static void sisfb_search_mode(char *name, bool quiet)
 
 	if(strlen(name) <= 19) {
 		strcpy(strbuf1, name);
-		for(i = 0; i < strlen(strbuf1); i++) {
+		for(i = 0; strbuf1[i]; i++) {
 			if(strbuf1[i] < '0' || strbuf1[i] > '9') strbuf1[i] = ' ';
 		}
 
-- 
2.1.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] drivers/video/fbdev/sis/sis_main.c: avoid repeated strlen() calls
  2015-06-09 13:04 [PATCH] drivers/video/fbdev/sis/sis_main.c: avoid repeated strlen() calls Rasmus Villemoes
@ 2015-06-12  9:36 ` Tomi Valkeinen
  0 siblings, 0 replies; 2+ messages in thread
From: Tomi Valkeinen @ 2015-06-12  9:36 UTC (permalink / raw)
  To: Rasmus Villemoes, Thomas Winischhofer, Jean-Christophe Plagniol-Villard
  Cc: linux-fbdev, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 374 bytes --]



On 09/06/15 16:04, Rasmus Villemoes wrote:
> gcc is not smart enough to realize that strlen(strbuf1) cannot be
> changed by the loop body, so it is forced to recompute it, at least in
> the branch containing the assignment. Avoid this by using an
> equivalent stopping condition.

Does it matter? Is sisfb calling sisfb_search_mode thousands of times?

 Tomi


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-06-12  9:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-09 13:04 [PATCH] drivers/video/fbdev/sis/sis_main.c: avoid repeated strlen() calls Rasmus Villemoes
2015-06-12  9:36 ` Tomi Valkeinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).