mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-28 07:18:30 +00:00
Improve performance of printf functions
This commit is contained in:
parent
b107d2709f
commit
dc6d11a031
39 changed files with 577 additions and 650 deletions
|
@ -19,6 +19,26 @@
|
|||
#include "libc/str/str.h"
|
||||
#include "net/http/http.h"
|
||||
|
||||
// -_0-9A-Za-z
|
||||
static const char kHostChars[256] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x00
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x10
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, // 0x20
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, // 0x30
|
||||
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x40
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, // 0x50
|
||||
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x60
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, // 0x70
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x80
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x90
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0xa0
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0xb0
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0xc0
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0xd0
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0xe0
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0xf0
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if host seems legit.
|
||||
*
|
||||
|
@ -49,33 +69,35 @@
|
|||
*/
|
||||
bool IsAcceptableHost(const char *s, size_t n) {
|
||||
size_t i;
|
||||
bool isip;
|
||||
int c, b, j;
|
||||
if (n == -1) n = s ? strlen(s) : 0;
|
||||
if (!n) return true;
|
||||
for (isip = true, b = j = i = 0; i < n; ++i) {
|
||||
for (b = j = i = 0; i < n; ++i) {
|
||||
c = s[i] & 255;
|
||||
if (c == '.' && (!i || s[i - 1] == '.')) {
|
||||
return false;
|
||||
} else if (!(isalnum(c) || c == '-' || c == '_' || c == '.')) {
|
||||
return false;
|
||||
}
|
||||
if (isip) {
|
||||
if (isdigit(c)) {
|
||||
b *= 10;
|
||||
b += c - '0';
|
||||
if (b > 255) {
|
||||
if (isdigit(c)) {
|
||||
b *= 10;
|
||||
b += c - '0';
|
||||
if (b > 255) {
|
||||
return false;
|
||||
}
|
||||
} else if (c == '.') {
|
||||
if (!i || s[i - 1] == '.') return false;
|
||||
b = 0;
|
||||
++j;
|
||||
} else {
|
||||
for (;;) {
|
||||
if (!kHostChars[c] && (c != '.' || (!i || s[i - 1] == '.'))) {
|
||||
return false;
|
||||
}
|
||||
} else if (c == '.') {
|
||||
b = 0;
|
||||
++j;
|
||||
} else {
|
||||
isip = false;
|
||||
if (++i < n) {
|
||||
c = s[i] & 255;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isip && j != 3) return false;
|
||||
if (j != 3) return false;
|
||||
if (i && s[i - 1] == '.') return false;
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue