Browse Source

Cleanup

master
cancel 6 years ago
parent
commit
21e1608d99
  1. 31
      sim.c

31
sim.c

@ -15,21 +15,7 @@ enum { Glyphs_array_num = sizeof indexed_glyphs };
// Always returns 0 through (sizeof indexed_glyphs) - 1, and works on // Always returns 0 through (sizeof indexed_glyphs) - 1, and works on
// capitalized glyphs as well. The index of the lower-cased glyph is returned // capitalized glyphs as well. The index of the lower-cased glyph is returned
// if the glyph is capitalized. // if the glyph is capitalized.
#if 0 #if 1
inline static Glyph glyph_lowered(Glyph c) {
return (c >= 'A' && c <= 'Z') ? (char)(c - ('a' - 'A')) : c;
}
static Usz index_of(Glyph c) {
Glyph c0 = glyph_lowered(c);
if (c0 == '.')
return 0;
for (Usz i = 0; i < Glyphs_array_num; ++i) {
if (indexed_glyphs[i] == c0)
return i;
}
return 0;
}
#else
static Usz index_of(Glyph c) { static Usz index_of(Glyph c) {
if (c == '.') if (c == '.')
return 0; return 0;
@ -51,6 +37,21 @@ static Usz index_of(Glyph c) {
} }
return 0; return 0;
} }
#else
// Reference implementation
inline static Glyph glyph_lowered(Glyph c) {
return (c >= 'A' && c <= 'Z') ? (char)(c - ('a' - 'A')) : c;
}
static Usz index_of(Glyph c) {
Glyph c0 = glyph_lowered(c);
if (c0 == '.')
return 0;
for (Usz i = 0; i < Glyphs_array_num; ++i) {
if (indexed_glyphs[i] == c0)
return i;
}
return 0;
}
#endif #endif
static inline Glyph glyph_of(Usz index) { static inline Glyph glyph_of(Usz index) {

Loading…
Cancel
Save