summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@iohq.net>2015-02-23 12:17:01 -0700
committerAaron Ball <nullspoon@iohq.net>2015-02-23 12:17:01 -0700
commit51875f1df0ff358924eaee6bf90836b1743b52f6 (patch)
treeedaaaca187334c193e2fdea7c0a0ec9dd0d4f5ba /src
parent6225bb83c6f5f569f2994bd2be1915f3aa66c7bf (diff)
downloadnoteless-51875f1df0ff358924eaee6bf90836b1743b52f6.tar.gz
noteless-51875f1df0ff358924eaee6bf90836b1743b52f6.tar.xz
Increased efficacy of itoc int to char conversion
Was using a series of if statements. This changes the operation so it just adds 48 to the integer's given mod to get the ascii index of its corresponding char.
Diffstat (limited to 'src')
-rw-r--r--src/common.c23
1 files changed, 2 insertions, 21 deletions
diff --git a/src/common.c b/src/common.c
index 7cbdc3e..81f5641 100644
--- a/src/common.c
+++ b/src/common.c
@@ -64,27 +64,8 @@ int itoc(int num, char* out) {
while(count >= 0) {
int n = num%10;
- if(n == 0) {
- out[count] = '0';
- } else if(n == 1) {
- out[count] = '1';
- } else if(n == 2) {
- out[count] = '2';
- } else if(n == 3) {
- out[count] = '3';
- } else if(n == 4) {
- out[count] = '4';
- } else if(n == 5) {
- out[count] = '5';
- } else if(n == 6) {
- out[count] = '6';
- } else if(n == 7) {
- out[count] = '7';
- } else if(n == 8) {
- out[count] = '8';
- } else if(n == 9) {
- out[count] = '9';
- }
+ // Add 48 to the int to get its char equivelant ascii index
+ out[count] = n + 48;
num /= 10;
count--;

Generated by cgit