<commit_before>#include <system.h>

#include <dux/drivers/core/console.h>

#ifndef __GNUC__
#error I want gcc!
#endif

#define va_start(v,l) __builtin_va_start(v,l)
#define va_arg(v,l)   __builtin_va_arg(v,l)
#define va_end(v)     __builtin_va_end(v)
#define va_copy(d,s)  __builtin_va_copy(d,s)
typedef __builtin_va_list va_list;

static void printn(unsigned int n, unsigned int base)
{
	char *numbers = "0123456789abcdefghijklmnopqrstuvwxyz";
	if (n / base)
		printn(n/base, base);
	console_writeb(numbers[n % base]);
}

void printk(const char *fmt, ...)
{
	va_list ap;
	const char *p, *sval;
	char cval;
	unsigned int ival;
	unsigned long long lval;
	unsigned int process_long = 0;
	//double dval; /* for %f */

	va_start(ap, fmt);
	for (p = fmt; *p; p++) {
		if (*p != '%') {
			console_writeb(*p);
			continue;
		}

reset:
		switch(*++p) {
			case 'i':
			case 'd':
				ival = va_arg(ap, unsigned int);
				printn(ival, 10);
				break;
			case 'c':
				cval = va_arg(ap, unsigned int);
				console_writeb(cval);
				break;
			case 's':
				sval = va_arg(ap, char*);
				while (*sval)
					console_writeb(*sval++);
				break;
			case 'x':
				if (process_long) {
					lval = va_arg(ap, unsigned long long);
					printn((unsigned int)lval, 16);
				} else {
					ival = va_arg(ap, unsigned int);
					printn(ival, 16);
				}
				break;
			case 'l':
				process_long = 1;
				goto reset;
				break;
			default:
				console_writeb(*p);
				break;
		}
	}
	va_end(ap);
}
<commit_msg>Moved numbers to a static variable outside the function for performance.<commit_after>#include <system.h>

#include <dux/drivers/core/console.h>

#ifndef __GNUC__
#error I want gcc!
#endif

#define va_start(v,l) __builtin_va_start(v,l)
#define va_arg(v,l)   __builtin_va_arg(v,l)
#define va_end(v)     __builtin_va_end(v)
#define va_copy(d,s)  __builtin_va_copy(d,s)
typedef __builtin_va_list va_list;

static const char *numbers = "0123456789abcdefghijklmnopqrstuvwxyz";

static void printn(unsigned int n, unsigned int base)
{
	if (n / base)
		printn(n/base, base);
	console_writeb(numbers[n % base]);
}

void printk(const char *fmt, ...)
{
	va_list ap;
	const char *p, *sval;
	char cval;
	unsigned int ival;
	unsigned long long lval;
	unsigned int process_long = 0;
	//double dval; /* for %f */

	va_start(ap, fmt);
	for (p = fmt; *p; p++) {
		if (*p != '%') {
			console_writeb(*p);
			continue;
		}

reset:
		switch(*++p) {
			case 'i':
			case 'd':
				ival = va_arg(ap, unsigned int);
				printn(ival, 10);
				break;
			case 'c':
				cval = va_arg(ap, unsigned int);
				console_writeb(cval);
				break;
			case 's':
				sval = va_arg(ap, char*);
				while (*sval)
					console_writeb(*sval++);
				break;
			case 'x':
				if (process_long) {
					lval = va_arg(ap, unsigned long long);
					printn((unsigned int)lval, 16);
				} else {
					ival = va_arg(ap, unsigned int);
					printn(ival, 16);
				}
				break;
			case 'l':
				process_long = 1;
				goto reset;
				break;
			default:
				console_writeb(*p);
				break;
		}
	}
	va_end(ap);
}

{'fraction_non_alphanumeric': 0.1492094861660079, 'fraction_numerical': 0.011857707509881422, 'mean_word_length': 3.265449438202247, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7513447', 'n_tokens_mistral': 1476, 'n_tokens_neox': 1239, 'n_words': 298}