mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-28 13:30:29 +00:00
Brush up some more code
This commit is contained in:
parent
ee6566a152
commit
a2d269dc38
32 changed files with 251 additions and 335 deletions
8
third_party/chibicc/as.c
vendored
8
third_party/chibicc/as.c
vendored
|
@ -1894,7 +1894,7 @@ static bool Prefix(struct As *a, const char *p, int n) {
|
|||
l = 0;
|
||||
r = ARRAYLEN(kPrefix) - 1;
|
||||
while (l <= r) {
|
||||
m = (l + r) >> 1;
|
||||
m = (l & r) + ((l ^ r) >> 1); // floor((a+b)/2)
|
||||
y = READ64BE(kPrefix[m]);
|
||||
if (x < y) {
|
||||
r = m - 1;
|
||||
|
@ -1919,7 +1919,7 @@ static bool FindReg(const char *p, int n, struct Reg *out_reg) {
|
|||
l = 0;
|
||||
r = ARRAYLEN(kRegs) - 1;
|
||||
while (l <= r) {
|
||||
m = (l + r) >> 1;
|
||||
m = (l & r) + ((l ^ r) >> 1); // floor((a+b)/2)
|
||||
y = READ64BE(kRegs[m].s);
|
||||
if (x < y) {
|
||||
r = m - 1;
|
||||
|
@ -3740,7 +3740,7 @@ static bool OnDirective8(struct As *a, struct Slice s) {
|
|||
l = 0;
|
||||
r = ARRAYLEN(kDirective8) - 1;
|
||||
while (l <= r) {
|
||||
m = (l + r) >> 1;
|
||||
m = (l & r) + ((l ^ r) >> 1); // floor((a+b)/2)
|
||||
y = READ64BE(kDirective8[m].s);
|
||||
if (x < y) {
|
||||
r = m - 1;
|
||||
|
@ -3763,7 +3763,7 @@ static bool OnDirective16(struct As *a, struct Slice s) {
|
|||
l = 0;
|
||||
r = ARRAYLEN(kDirective16) - 1;
|
||||
while (l <= r) {
|
||||
m = (l + r) >> 1;
|
||||
m = (l & r) + ((l ^ r) >> 1); // floor((a+b)/2)
|
||||
y = READ128BE(kDirective16[m].s);
|
||||
if (x < y) {
|
||||
r = m - 1;
|
||||
|
|
2
third_party/linenoise/linenoise.c
vendored
2
third_party/linenoise/linenoise.c
vendored
|
@ -313,7 +313,7 @@ static unsigned GetMirror(const unsigned short A[][2], size_t n, unsigned c) {
|
|||
l = 0;
|
||||
r = n - 1;
|
||||
while (l <= r) {
|
||||
m = (l + r) >> 1;
|
||||
m = (l & r) + ((l ^ r) >> 1); // floor((a+b)/2)
|
||||
if (A[m][0] < c) {
|
||||
l = m + 1;
|
||||
} else if (A[m][0] > c) {
|
||||
|
|
2
third_party/maxmind/getmetroname.c
vendored
2
third_party/maxmind/getmetroname.c
vendored
|
@ -244,7 +244,7 @@ const char *GetMetroName(int code) {
|
|||
l = 0;
|
||||
r = ARRAYLEN(kMetroNames) - 1;
|
||||
while (l <= r) {
|
||||
m = (l + r) >> 1;
|
||||
m = (l & r) + ((l ^ r) >> 1); // floor((a+b)/2)
|
||||
if (kMetroNames[m].code < code) {
|
||||
l = m + 1;
|
||||
} else if (kMetroNames[m].code > code) {
|
||||
|
|
|
@ -3901,7 +3901,7 @@ double _PyUnicode_ToNumeric(Py_UCS4 c)
|
|||
l = 0;
|
||||
r = sizeof(kNumericCodes) / sizeof(kNumericCodes[0]) - 1;
|
||||
while (l <= r) {
|
||||
m = (l + r) >> 1;
|
||||
m = (l & r) + ((l ^ r) >> 1); // floor((a+b)/2)
|
||||
if (kNumericCodes[m] < c) {
|
||||
l = m + 1;
|
||||
} else if (kNumericCodes[m] > c) {
|
||||
|
@ -3914,7 +3914,7 @@ double _PyUnicode_ToNumeric(Py_UCS4 c)
|
|||
l = 0;
|
||||
r = sizeof(kNumericAstralCodes) / sizeof(kNumericAstralCodes[0]) - 1;
|
||||
while (l <= r) {
|
||||
m = (l + r) >> 1;
|
||||
m = (l & r) + ((l ^ r) >> 1); // floor((a+b)/2)
|
||||
if (kNumericAstralCodes[m] < c) {
|
||||
l = m + 1;
|
||||
} else if (kNumericAstralCodes[m] > c) {
|
||||
|
|
|
@ -456,7 +456,7 @@ double _PyUnicode_ToNumeric(Py_UCS4 c)
|
|||
l = 0;
|
||||
r = sizeof(kNumericCodes) / sizeof(kNumericCodes[0]) - 1;
|
||||
while (l <= r) {
|
||||
m = (l + r) >> 1;
|
||||
m = (l & r) + ((l ^ r) >> 1); // floor((a+b)/2)
|
||||
if (kNumericCodes[m] < c) {
|
||||
l = m + 1;
|
||||
} else if (kNumericCodes[m] > c) {
|
||||
|
@ -469,7 +469,7 @@ double _PyUnicode_ToNumeric(Py_UCS4 c)
|
|||
l = 0;
|
||||
r = sizeof(kNumericAstralCodes) / sizeof(kNumericAstralCodes[0]) - 1;
|
||||
while (l <= r) {
|
||||
m = (l + r) >> 1;
|
||||
m = (l & r) + ((l ^ r) >> 1); // floor((a+b)/2)
|
||||
if (kNumericAstralCodes[m] < c) {
|
||||
l = m + 1;
|
||||
} else if (kNumericAstralCodes[m] > c) {
|
||||
|
|
2
third_party/python/pyobj.c
vendored
2
third_party/python/pyobj.c
vendored
|
@ -414,7 +414,7 @@ IsIgnoredModule(const char *s)
|
|||
l = 0;
|
||||
r = ARRAYLEN(kIgnoredModules) - 1;
|
||||
while (l <= r) {
|
||||
m = (l + r) >> 1;
|
||||
m = (l & r) + ((l ^ r) >> 1); // floor((a+b)/2)
|
||||
x = strcmp(s, kIgnoredModules[m]);
|
||||
if (x < 0) {
|
||||
r = m - 1;
|
||||
|
|
12
third_party/stb/stb_truetype.c
vendored
12
third_party/stb/stb_truetype.c
vendored
|
@ -25,6 +25,7 @@
|
|||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/stb/stb_truetype.h"
|
||||
#include "libc/assert.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/intrin/likely.h"
|
||||
|
@ -34,7 +35,6 @@
|
|||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "third_party/stb/stb_rect_pack.h"
|
||||
#include "third_party/stb/stb_truetype.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
stb_truetype (MIT License)\\n\
|
||||
|
@ -1562,7 +1562,7 @@ static int stbtt__GetGlyphKernInfoAdvance(const stbtt_fontinfo *info, int glyph1
|
|||
r = ttUSHORT(data+10) - 1;
|
||||
needle = glyph1 << 16 | glyph2;
|
||||
while (l <= r) {
|
||||
m = (l + r) >> 1;
|
||||
m = (l & r) + ((l ^ r) >> 1); // floor((a+b)/2)
|
||||
straw = ttULONG(data+18+(m*6)); // note: unaligned read
|
||||
if (needle < straw)
|
||||
r = m - 1;
|
||||
|
@ -1586,7 +1586,7 @@ static int32_t stbtt__GetCoverageIndex(uint8_t *coverageTable, int glyph)
|
|||
while (l <= r) {
|
||||
uint8_t *glyphArray = coverageTable + 4;
|
||||
uint16_t glyphID;
|
||||
m = (l + r) >> 1;
|
||||
m = (l & r) + ((l ^ r) >> 1); // floor((a+b)/2)
|
||||
glyphID = ttUSHORT(glyphArray + 2 * m);
|
||||
straw = glyphID;
|
||||
if (needle < straw)
|
||||
|
@ -1607,7 +1607,7 @@ static int32_t stbtt__GetCoverageIndex(uint8_t *coverageTable, int glyph)
|
|||
int strawStart, strawEnd, needle=glyph;
|
||||
while (l <= r) {
|
||||
uint8_t *rangeRecord;
|
||||
m = (l + r) >> 1;
|
||||
m = (l & r) + ((l ^ r) >> 1); // floor((a+b)/2)
|
||||
rangeRecord = rangeArray + 6 * m;
|
||||
strawStart = ttUSHORT(rangeRecord);
|
||||
strawEnd = ttUSHORT(rangeRecord + 2);
|
||||
|
@ -1648,7 +1648,7 @@ static int32_t stbtt__GetGlyphClass(uint8_t *classDefTable, int glyph)
|
|||
int strawStart, strawEnd, needle=glyph;
|
||||
while (l <= r) {
|
||||
uint8_t *classRangeRecord;
|
||||
m = (l + r) >> 1;
|
||||
m = (l & r) + ((l ^ r) >> 1); // floor((a+b)/2)
|
||||
classRangeRecord = classRangeRecords + 6 * m;
|
||||
strawStart = ttUSHORT(classRangeRecord);
|
||||
strawEnd = ttUSHORT(classRangeRecord + 2);
|
||||
|
@ -1719,7 +1719,7 @@ static int32_t stbtt__GetGlyphGPOSInfoAdvance(const stbtt_fontinfo *info, int gl
|
|||
while (l <= r) {
|
||||
uint16_t secondGlyph;
|
||||
uint8_t *pairValue;
|
||||
m = (l + r) >> 1;
|
||||
m = (l & r) + ((l ^ r) >> 1); // floor((a+b)/2)
|
||||
pairValue = pairValueArray + (2 + valueRecordPairSizeInBytes) * m;
|
||||
secondGlyph = ttUSHORT(pairValue);
|
||||
straw = secondGlyph;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue