Brush up some more code

This commit is contained in:
Justine Tunney 2023-07-10 10:16:55 -07:00
parent ee6566a152
commit a2d269dc38
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
32 changed files with 251 additions and 335 deletions

View file

@ -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;