avr-libc-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-libc-commit] [2350] Re-work of isotime_r() improves cpu usage.


From: Mike Rice
Subject: [avr-libc-commit] [2350] Re-work of isotime_r() improves cpu usage.
Date: Thu, 18 Apr 2013 20:33:16 +0000

Revision: 2350
          http://svn.sv.gnu.org/viewvc/?view=rev&root=avr-libc&revision=2350
Author:   swfltek
Date:     2013-04-18 20:33:15 +0000 (Thu, 18 Apr 2013)
Log Message:
-----------
Re-work of isotime_r() improves cpu usage.

Modified Paths:
--------------
    trunk/avr-libc/libc/time/isotime_r.c

Modified: trunk/avr-libc/libc/time/isotime_r.c
===================================================================
--- trunk/avr-libc/libc/time/isotime_r.c        2013-04-17 21:27:25 UTC (rev 
2349)
+++ trunk/avr-libc/libc/time/isotime_r.c        2013-04-18 20:33:15 UTC (rev 
2350)
@@ -35,21 +35,16 @@
 #include <stdlib.h>
 #include <time.h>
 
-char           *
-__printem(int i, char *buffer)
+void
+__printem(int i, char *buffer, char s)
 {
-       int             n = 0;
+    div_t result;
 
-       if (i < 10)
-               *buffer++ = '0';
-       itoa(i, buffer, 10);
+    result = div(i, 10);
 
-       do {
-               n++;
-               i /= 10;
-       } while (i);
-
-       return buffer + n;
+       *buffer++ = result.quot + '0';
+       *buffer++ = result.rem + '0';
+       *buffer = s;
 }
 
 void
@@ -58,27 +53,28 @@
        int             i;
 
        i = tmptr->tm_year + 1900;
-       buffer = __printem(i, buffer);
-       *buffer++ = '-';
+       __printem(i/100, buffer, '-');
+       buffer+=2;
+       __printem(i%100, buffer,'-');
+       buffer+=3;
 
        i = tmptr->tm_mon + 1;
-       buffer = __printem(i, buffer);
-       *buffer++ = '-';
+       __printem(i, buffer,'-');
+       buffer+=3;
 
        i = tmptr->tm_mday;
-       buffer = __printem(i, buffer);
-       *buffer++ = ' ';
+       __printem(i, buffer,' ');
+       buffer+=3;
 
        i = tmptr->tm_hour;
-       buffer = __printem(i, buffer);
-       *buffer++ = ':';
+       __printem(i, buffer,':');
+       buffer+=3;
 
        i = tmptr->tm_min;
-       buffer = __printem(i, buffer);
-       *buffer++ = ':';
+       __printem(i, buffer,':');
+       buffer+=3;
 
        i = tmptr->tm_sec;
-       buffer = __printem(i, buffer);
+       __printem(i, buffer,0);
 
-       *buffer++ = 0;
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]