mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 05:42:29 +00:00
Reduce GNU Make latency 17% for cosmo
fgets() is now 4x faster which makes Make 2% faster. Landlock Make now has a builtin $(uniq ...) function that uses critbit trees rather than functional programming. Since uniq is the most important function this optimization makes our cold start latency 15% faster.
This commit is contained in:
parent
8835b82a7c
commit
d76dfadc7a
7 changed files with 96 additions and 11 deletions
|
@ -16,8 +16,12 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
* Reads line from stream.
|
||||
|
@ -33,20 +37,33 @@
|
|||
* zero characters have been read
|
||||
*/
|
||||
char *fgets_unlocked(char *s, int size, FILE *f) {
|
||||
int c;
|
||||
char *p;
|
||||
int c, n;
|
||||
char *p, *b, *t;
|
||||
p = s;
|
||||
if (size > 0) {
|
||||
while (--size > 0) {
|
||||
if ((c = fgetc_unlocked(f)) == -1) {
|
||||
if (ferror_unlocked(f) == EINTR) {
|
||||
continue;
|
||||
} else {
|
||||
break;
|
||||
if (!IsTiny() && f->beg < f->end) {
|
||||
b = f->buf + f->beg;
|
||||
n = MIN(f->end - f->beg, size);
|
||||
if ((t = memchr(b, '\n', n))) {
|
||||
n = t + 1 - b;
|
||||
}
|
||||
memcpy(p, b, n);
|
||||
f->beg += n;
|
||||
size -= n - 1;
|
||||
p += n;
|
||||
if (t) break;
|
||||
} else {
|
||||
if ((c = fgetc_unlocked(f)) == -1) {
|
||||
if (ferror_unlocked(f) == EINTR) {
|
||||
continue;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
*p++ = c & 255;
|
||||
if (c == '\n') break;
|
||||
}
|
||||
*p++ = c & 255;
|
||||
if (c == '\n') break;
|
||||
}
|
||||
*p = '\0';
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue