Merge pull request #76 from memtest86plus/debrouxl/size_optimizations
Save space by inlining functions and getting rid of library functions which become unused
This commit is contained in:
commit
4b17a4cc0c
|
@ -38,7 +38,6 @@ SYS_OBJS = system/cpuid.o \
|
|||
system/xhci.o
|
||||
|
||||
LIB_OBJS = lib/barrier.o \
|
||||
lib/ctype.o \
|
||||
lib/div64.o \
|
||||
lib/print.o \
|
||||
lib/read.o \
|
||||
|
|
|
@ -38,7 +38,6 @@ SYS_OBJS = system/cpuid.o \
|
|||
system/xhci.o
|
||||
|
||||
LIB_OBJS = lib/barrier.o \
|
||||
lib/ctype.o \
|
||||
lib/print.o \
|
||||
lib/read.o \
|
||||
lib/string.o \
|
||||
|
|
27
lib/ctype.c
27
lib/ctype.c
|
@ -1,27 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
// Copyright (C) 2020 Martin Whitaker.
|
||||
|
||||
#include "ctype.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Public Functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
int toupper(int c)
|
||||
{
|
||||
if (c >= 'a' && c <= 'z') {
|
||||
return c + 'A' -'a';
|
||||
} else {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
int isdigit(int c)
|
||||
{
|
||||
return c >= '0' && c <= '9';
|
||||
}
|
||||
|
||||
int isxdigit(int c)
|
||||
{
|
||||
return isdigit(c) || (toupper(c) >= 'A' && toupper(c) <= 'F');
|
||||
}
|
19
lib/ctype.h
19
lib/ctype.h
|
@ -14,18 +14,31 @@
|
|||
* If c is a lower-case letter, returns its upper-case equivalent, otherwise
|
||||
* returns c. Assumes c is an ASCII character.
|
||||
*/
|
||||
int toupper(int c);
|
||||
static inline int toupper(int c)
|
||||
{
|
||||
if (c >= 'a' && c <= 'z') {
|
||||
return c + 'A' -'a';
|
||||
} else {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns 1 if c is a decimal digit, otherwise returns 0. Assumes c is an
|
||||
* ASCII character.
|
||||
*/
|
||||
int isdigit(int c);
|
||||
static inline int isdigit(int c)
|
||||
{
|
||||
return c >= '0' && c <= '9';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns 1 if c is a hexadecimal digit, otherwise returns 0. Assumes c is an
|
||||
* ASCII character.
|
||||
*/
|
||||
int isxdigit(int c);
|
||||
static inline int isxdigit(int c)
|
||||
{
|
||||
return isdigit(c) || (toupper(c) >= 'A' && toupper(c) <= 'F');
|
||||
}
|
||||
|
||||
#endif // CTYPE_H
|
||||
|
|
20
lib/string.c
20
lib/string.c
|
@ -43,16 +43,6 @@ int memcmp(const void *s1, const void *s2, size_t n)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void *memcpy(void *dest, const void *src, size_t n)
|
||||
{
|
||||
char *d = (char *)dest, *s = (char *)src;
|
||||
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
d[i] = s[i];
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
void *memmove(void *dest, const void *src, size_t n)
|
||||
{
|
||||
char *d = (char *)dest, *s = (char *)src;
|
||||
|
@ -74,16 +64,6 @@ void *memmove(void *dest, const void *src, size_t n)
|
|||
return dest;
|
||||
}
|
||||
|
||||
void *memset(void *s, int c, size_t n)
|
||||
{
|
||||
char *d = (char *)s;
|
||||
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
d[i] = c;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
size_t strlen(const char *s)
|
||||
{
|
||||
size_t len = 0;
|
||||
|
|
|
@ -24,8 +24,9 @@ int memcmp(const void *s1, const void *s2, size_t n);
|
|||
* Copies n bytes from the memory area pointed to by src to the memory area
|
||||
* pointed to by dest and returns a pointer to dest. The memory areas must
|
||||
* not overlap.
|
||||
* void *memcpy(void *dst, const void *src, size_t n);
|
||||
*/
|
||||
void *memcpy(void *dst, const void *src, size_t n);
|
||||
#define memcpy(d, s, n) __builtin_memcpy((d), (s), (n))
|
||||
|
||||
/**
|
||||
* Copies n bytes from the memory area pointed to by src to the memory area
|
||||
|
@ -37,8 +38,9 @@ void *memmove(void *dest, const void *src, size_t n);
|
|||
/**
|
||||
* Fills the first n bytes of the memory area pointed to by s with the byte
|
||||
* value c.
|
||||
* void *memset(void *s, int c, size_t n);
|
||||
*/
|
||||
void *memset(void *s, int c, size_t n);
|
||||
#define memset(s, c, n) __builtin_memset((s), (c), (n))
|
||||
|
||||
/**
|
||||
* Returns the string length, excluding the terminating null character.
|
||||
|
|
Loading…
Reference in New Issue