Optimize the bit twiddling in sprite_position_for
This commit is contained in:
parent
4ce9f550ac
commit
8ee1c851a1
@ -14,6 +14,8 @@
|
|||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#define UNUSED __attribute__ ((unused))
|
#define UNUSED __attribute__ ((unused))
|
||||||
#define EXPORTED __attribute__ ((visibility ("default")))
|
#define EXPORTED __attribute__ ((visibility ("default")))
|
||||||
|
#define LIKELY(x) __builtin_expect (!!(x), 1)
|
||||||
|
#define UNLIKELY(x) __builtin_expect (!!(x), 0)
|
||||||
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
|
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
|
||||||
#define MIN(x, y) (((x) > (y)) ? (y) : (x))
|
#define MIN(x, y) (((x) > (y)) ? (y) : (x))
|
||||||
#define xstr(s) str(s)
|
#define xstr(s) str(s)
|
||||||
@ -45,6 +47,7 @@ typedef unsigned int index_type;
|
|||||||
#define DECORATION_MASK 3
|
#define DECORATION_MASK 3
|
||||||
#define BOLD_SHIFT 4
|
#define BOLD_SHIFT 4
|
||||||
#define ITALIC_SHIFT 5
|
#define ITALIC_SHIFT 5
|
||||||
|
#define POSCHAR_MASK 0x30FFFFFF
|
||||||
#define REVERSE_SHIFT 6
|
#define REVERSE_SHIFT 6
|
||||||
#define STRIKE_SHIFT 7
|
#define STRIKE_SHIFT 7
|
||||||
#define COL_MASK 0xFFFFFFFF
|
#define COL_MASK 0xFFFFFFFF
|
||||||
|
|||||||
@ -77,12 +77,11 @@ do_increment(SpriteMap *self, int *error) {
|
|||||||
|
|
||||||
static SpritePosition*
|
static SpritePosition*
|
||||||
sprite_position_for(SpriteMap *self, char_type ch, combining_type cc, bool is_second, int *error) {
|
sprite_position_for(SpriteMap *self, char_type ch, combining_type cc, bool is_second, int *error) {
|
||||||
char_type attrs = ch >> ATTRS_SHIFT, pos_char;
|
char_type pos_char = ch & POSCHAR_MASK; // Includes only the char and bold and italic bits
|
||||||
uint8_t bold = (attrs >> BOLD_SHIFT) & 1, italic = (attrs >> ITALIC_SHIFT) & 1;
|
unsigned int idx = ((ch >> (ATTRS_SHIFT - 6)) & 0x300) | (ch & 0xFF); // Includes only italic, bold and lowest byte of ch
|
||||||
size_t idx = (ch & 0xff) | (bold << 8) | (italic << 9);
|
|
||||||
attrs = bold << BOLD_SHIFT | italic << ITALIC_SHIFT;
|
|
||||||
pos_char = (ch & CHAR_MASK) | (attrs << ATTRS_SHIFT);
|
|
||||||
SpritePosition *s = &(self->cache[idx]);
|
SpritePosition *s = &(self->cache[idx]);
|
||||||
|
// Optimize for the common case of an ASCII char already in the cache
|
||||||
|
if (LIKELY(s->ch == pos_char && s->filled && s->cc == cc && s->is_second == is_second)) return s; // Cache hit
|
||||||
while(true) {
|
while(true) {
|
||||||
if (s->filled) {
|
if (s->filled) {
|
||||||
if (s->ch == pos_char && s->cc == cc && s->is_second == is_second) return s; // Cache hit
|
if (s->ch == pos_char && s->cc == cc && s->is_second == is_second) return s; // Cache hit
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user