Merge pull request #5310 from mysterywolf/printf2

[kservice] 优化RT_PRINTF_LONGLONG,减少重复代码
This commit is contained in:
Bernard Xiong authored and GitHub committed 2021-11-29 02:14:18 +08:00
commit 9c78680f36
2 files changed
+133 -151

No files matched your search

+111 -111
View File
File diff suppressed because it is too large. Load diff
+22 -40
View File
@@ -593,7 +593,6 @@ RTM_EXPORT(rt_show_version);
/* private function */
#define _ISDIGIT(c) ((unsigned)((c) - '0') < 10)
#ifdef RT_PRINTF_LONGLONG
/**
* This function will duplicate a string.
*
@@ -603,44 +602,38 @@ RTM_EXPORT(rt_show_version);
*
* @return the duplicated string pointer.
*/
#ifdef RT_PRINTF_LONGLONG
rt_inline int divide(long long *n, int base)
{
int res;
/* optimized for processor which does not support divide instructions. */
if (base == 10)
{
res = (int)(((unsigned long long)*n) % 10U);
*n = (long long)(((unsigned long long)*n) / 10U);
}
else
{
res = (int)(((unsigned long long)*n) % 16U);
*n = (long long)(((unsigned long long)*n) / 16U);
}
return res;
}
#else
rt_inline int divide(long *n, int base)
#endif /* RT_PRINTF_LONGLONG */
{
int res;
/* optimized for processor which does not support divide instructions. */
if (base == 10)
{
#ifdef RT_PRINTF_LONGLONG
res = (int)(((unsigned long long)*n) % 10U);
*n = (long long)(((unsigned long long)*n) / 10U);
#else
res = (int)(((unsigned long)*n) % 10U);
*n = (long)(((unsigned long)*n) / 10U);
#endif
}
else
{
#ifdef RT_PRINTF_LONGLONG
res = (int)(((unsigned long long)*n) % 16U);
*n = (long long)(((unsigned long long)*n) / 16U);
#else
res = (int)(((unsigned long)*n) % 16U);
*n = (long)(((unsigned long)*n) / 16U);
#endif
}
return res;
}
#endif /* RT_PRINTF_LONGLONG */
rt_inline int skip_atoi(const char **s)
{
@@ -659,30 +652,19 @@ rt_inline int skip_atoi(const char **s)
#define SPECIAL (1 << 5) /* 0x */
#define LARGE (1 << 6) /* use 'ABCDEF' instead of 'abcdef' */
static char *print_number(char *buf,
char *end,
#ifdef RT_PRINTF_LONGLONG
long long num,
#else
long num,
#endif /* RT_PRINTF_LONGLONG */
int base,
int s,
#ifdef RT_PRINTF_PRECISION
static char *print_number(char *buf,
char *end,
#ifdef RT_PRINTF_LONGLONG
long long num,
#else
long num,
#endif /* RT_PRINTF_LONGLONG */
int base,
int s,
int precision,
int type)
#else
static char *print_number(char *buf,
char *end,
#ifdef RT_PRINTF_LONGLONG
long long num,
#else
long num,
#endif /* RT_PRINTF_LONGLONG */
int base,
int s,
int type)
#endif /* RT_PRINTF_PRECISION */
int type)
{
char c, sign;
#ifdef RT_PRINTF_LONGLONG