Skip to content

Commit 0e0c020

Browse files
committed
Reduced memory usage of default printf
1 parent 2c3ecc0 commit 0e0c020

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

Changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Version 6.2.0
22
- Made `virtual` a reserved keyword in C++
3+
- Reduced memory usage of default printf
34

45
Version 6.1.6
56
- Added ability to double quote to include quotes in literal BASIC strings

include/libc/unix/posixio.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ static vfs_file_t __filetab[_MAX_FILES] = {
5656
0, /* close function */
5757
&_rxtxioctl,
5858
&__dummy_flush, /* flush function */
59+
0, /* lseek */
60+
0, 0, /* pointer cache */
5961
},
6062
/* stdout */
6163
{
@@ -71,6 +73,8 @@ static vfs_file_t __filetab[_MAX_FILES] = {
7173
0, /* close function */
7274
&_rxtxioctl,
7375
&__dummy_flush, /* flush function */
76+
0, /* lseek */
77+
0, 0, /* pointer cache */
7478
},
7579
/* stderr */
7680
{
@@ -86,6 +90,8 @@ static vfs_file_t __filetab[_MAX_FILES] = {
8690
0, /* close function */
8791
&_rxtxioctl,
8892
&__dummy_flush, /* flush function */
93+
0, /* lseek */
94+
0, 0, /* pointer cache */
8995
},
9096
};
9197

include/libsys/fmt.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -909,13 +909,19 @@ TxFunc _gettxfunc(unsigned h) {
909909
vfs_file_t *v;
910910
v = __getftab(h);
911911
if (!v || !v->state) return 0;
912-
return (TxFunc)&v->putchar;
912+
if (!v->putchar_ptr) {
913+
v->putchar_ptr = &v->putchar;
914+
}
915+
return (TxFunc)v->putchar_ptr;
913916
}
914917
RxFunc _getrxfunc(unsigned h) {
915918
vfs_file_t *v;
916919
v = __getftab(h);
917920
if (!v || !v->state) return 0;
918-
return (RxFunc)&v->getchar;
921+
if (!v->getchar_ptr) {
922+
v->getchar_ptr = &v->getchar;
923+
}
924+
return (RxFunc)v->getchar_ptr;
919925
}
920926
static int *_getiolock(unsigned h) {
921927
vfs_file_t *v;

include/sys/types.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ struct s_vfs_file_t {
6262
/* internal functions for formatting routines */
6363
int putchar(int c) __fromfile("libsys/vfs.c");
6464
int getchar(void) __fromfile("libsys/vfs.c");
65+
66+
/* cache for pointers of the above functions */
67+
int (*putchar_ptr)(int c);
68+
int (*getchar_ptr)(void);
6569
};
6670

6771
typedef int (*putcfunc_t)(int c, vfs_file_t *fil);

0 commit comments

Comments
 (0)