improve C module

This commit is contained in:
Kinneyzhang 2026-01-26 01:24:47 +08:00
parent f42c2bda00
commit 136e53fe8e
5 changed files with 5 additions and 47 deletions

3
.gitignore vendored
View File

@ -1,4 +1,5 @@
.DS_Store
archive archive
*.dylib *.dylib
*.dll *.dll
*.o *.o

View File

@ -52,6 +52,7 @@ all: $(MODULE)
$(MODULE): $(OBJS) $(MODULE): $(OBJS)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
@rm -f $(OBJS)
@echo "Built $@" @echo "Built $@"
%.o: %.c ekp_module.h %.o: %.c ekp_module.h

View File

@ -620,11 +620,11 @@ static void defun(emacs_env *env, const char *name,
*/ */
int emacs_module_init(struct emacs_runtime *runtime) int emacs_module_init(struct emacs_runtime *runtime)
{ {
if (runtime->size < sizeof(*runtime)) if ((size_t)runtime->size < sizeof(*runtime))
return 1; return 1;
emacs_env *env = runtime->get_environment(runtime); emacs_env *env = runtime->get_environment(runtime);
if (env->size < sizeof(*env)) if ((size_t)env->size < sizeof(*env))
return 2; return 2;
/* Define functions */ /* Define functions */

View File

@ -81,30 +81,6 @@ static inline double compute_demerits(double badness, int32_t penalty,
return base; return base;
} }
/*
* Check if position is a hyphenation break
* Uses binary search for O(log n) lookup (positions are sorted)
*/
static inline bool is_hyphen_break(ekp_paragraph_t *p, size_t pos)
{
if (p->hyphen_count == 0)
return false;
/* Binary search in sorted hyphen_positions */
size_t lo = 0;
size_t hi = p->hyphen_count - 1;
while (lo < hi) {
size_t mid = lo + (hi - lo) / 2;
if ((size_t)p->hyphen_positions[mid] < pos)
lo = mid + 1;
else
hi = mid;
}
return (size_t)p->hyphen_positions[lo] == pos;
}
/* /*
* Parallel work item for demerits computation * Parallel work item for demerits computation
*/ */

View File

@ -22,15 +22,6 @@
#define GLUE_CWS 3 /* CJK character space */ #define GLUE_CWS 3 /* CJK character space */
/* UTF-8 helpers */ /* UTF-8 helpers */
static inline int utf8_char_len(unsigned char c)
{
if ((c & 0x80) == 0) return 1;
if ((c & 0xE0) == 0xC0) return 2;
if ((c & 0xF0) == 0xE0) return 3;
if ((c & 0xF8) == 0xF0) return 4;
return 1; /* invalid, treat as single byte */
}
static inline uint32_t utf8_decode(const char *s, int *len) static inline uint32_t utf8_decode(const char *s, int *len)
{ {
unsigned char c = s[0]; unsigned char c = s[0];
@ -82,15 +73,6 @@ static inline bool is_cjk_punct(uint32_t cp)
cp == 0x2018 || cp == 0x2019; /* ' ' */ cp == 0x2018 || cp == 0x2019; /* ' ' */
} }
static inline bool is_latin(uint32_t cp)
{
return (cp >= 'A' && cp <= 'Z') ||
(cp >= 'a' && cp <= 'z') ||
(cp >= 0xC0 && cp <= 0xFF) || /* Latin-1 Supplement */
(cp >= 0x100 && cp <= 0x24F) || /* Latin Extended */
(cp >= 0x1E00 && cp <= 0x1EFF); /* Latin Extended Additional */
}
static inline bool is_whitespace(uint32_t cp) static inline bool is_whitespace(uint32_t cp)
{ {
return cp == ' ' || cp == '\t' || cp == '\n' || cp == '\r' || return cp == ' ' || cp == '\t' || cp == '\n' || cp == '\r' ||
@ -179,7 +161,6 @@ ekp_paragraph_t *ekp_para_create(const char *text, size_t len,
/* Tokenize into boxes */ /* Tokenize into boxes */
size_t box_count = 0; size_t box_count = 0;
size_t pos = 0; size_t pos = 0;
uint8_t prev_type = BOX_SPACE;
size_t word_start = 0; size_t word_start = 0;
bool in_latin_word = false; bool in_latin_word = false;
@ -212,7 +193,6 @@ ekp_paragraph_t *ekp_para_create(const char *text, size_t len,
box_count++; box_count++;
} }
prev_type = type;
pos += char_len; pos += char_len;
} }