aboutsummaryrefslogtreecommitdiffstats
path: root/src/gwin
diff options
context:
space:
mode:
authorJoel Bodenmann <joel@seriouslyembedded.com>2015-08-14 18:47:55 +0200
committerJoel Bodenmann <joel@seriouslyembedded.com>2015-08-14 18:47:55 +0200
commitb828bf567bd6989cddb3259a65871f7460011f5d (patch)
treed1f472e54fd5f19faa4e0c73baae9b8b5d13448e /src/gwin
parentfcaa42972964e002474e6f79364f3af1a616d25c (diff)
downloaduGFX-b828bf567bd6989cddb3259a65871f7460011f5d.tar.gz
uGFX-b828bf567bd6989cddb3259a65871f7460011f5d.tar.bz2
uGFX-b828bf567bd6989cddb3259a65871f7460011f5d.zip
Optimizing string shift operations by using memcpy()
Diffstat (limited to 'src/gwin')
-rw-r--r--src/gwin/gwin_textedit.c22
1 files changed, 6 insertions, 16 deletions
diff --git a/src/gwin/gwin_textedit.c b/src/gwin/gwin_textedit.c
index 9c7990eb..999a91dd 100644
--- a/src/gwin/gwin_textedit.c
+++ b/src/gwin/gwin_textedit.c
@@ -16,7 +16,6 @@
#include "gwin_class.h"
#include <string.h>
-#include <stdio.h>
// Some settings
const int CURSOR_EXTRA_HEIGHT = 1;
@@ -28,7 +27,7 @@
// cursorPos is the position of the next character
// textBuffer[cursorPos++] = readKey();
-// ToDo: Optimize by using strncpy() instead
+// ToDo: Optimize by using memncpy() instead
static void _shiftTextLeft(char* buffer, size_t bufferSize, size_t index)
{
// Find the end of the string
@@ -38,14 +37,12 @@ static void _shiftTextLeft(char* buffer, size_t bufferSize, size_t index)
}
// Shift
- size_t i = 0;
- for (i = index; i < indexTerminator+1; i++) {
- buffer[i-1] = buffer[i];
- }
- buffer[indexTerminator] = '\0';
+ memcpy(&buffer[index-1], &buffer[index], indexTerminator-index);
+
+ // Terminate the string
+ buffer[indexTerminator-1] = '\0';
}
-// ToDo: Optimize by using strncpy() instead
static void _shiftTextRight(char* buffer, size_t bufferSize, size_t index, char fillChar)
{
// Find the end of the string
@@ -55,14 +52,7 @@ static void _shiftTextRight(char* buffer, size_t bufferSize, size_t index, char
}
// Shift
- size_t i = 0;
- for (i = indexTerminator+1; i > index; i--) {
- if (i > bufferSize-1) {
- break;
- }
-
- buffer[i] = buffer[i-1];
- }
+ memcpy(&buffer[index+1], &buffer[index], indexTerminator-index);
// Fill the gap
buffer[index] = fillChar;