Improve performance of printf functions

This commit is contained in:
Justine Tunney 2021-04-24 13:58:34 -07:00
parent b107d2709f
commit dc6d11a031
39 changed files with 577 additions and 650 deletions

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/fmt/fmt.h"
#include "libc/limits.h"
#include "libc/stdio/stdio.h"
@ -26,9 +27,17 @@ struct state {
int n;
};
static noinstrument int vfprintfputchar(int c, struct state *st) {
st->n++;
return fputc(c, st->f);
static int vfprintfputchar(const char *s, struct state *t, size_t n) {
if (n) {
if (n == 1 && *s != '\n' && t->f->beg < t->f->size &&
t->f->bufmode != _IONBF) {
t->f->buf[t->f->beg++] = *s;
} else if (!fwrite(s, 1, n, t->f)) {
return -1;
}
t->n += n;
}
return 0;
}
int(vfprintf)(FILE *f, const char *fmt, va_list va) {