From 136e53fe8e028e47c642d28f4ead4b09752e43bb Mon Sep 17 00:00:00 2001 From: Kinneyzhang Date: Mon, 26 Jan 2026 01:24:47 +0800 Subject: [PATCH] improve C module --- .gitignore | 3 ++- ekp_c/Makefile | 1 + ekp_c/ekp.c | 4 ++-- ekp_c/ekp_kp.c | 24 ------------------------ ekp_c/ekp_paragraph.c | 20 -------------------- 5 files changed, 5 insertions(+), 47 deletions(-) diff --git a/.gitignore b/.gitignore index 7636704..13667a8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ +.DS_Store archive *.dylib *.dll -*.o \ No newline at end of file +*.o diff --git a/ekp_c/Makefile b/ekp_c/Makefile index 6125fc8..d13a1a3 100644 --- a/ekp_c/Makefile +++ b/ekp_c/Makefile @@ -52,6 +52,7 @@ all: $(MODULE) $(MODULE): $(OBJS) $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) + @rm -f $(OBJS) @echo "Built $@" %.o: %.c ekp_module.h diff --git a/ekp_c/ekp.c b/ekp_c/ekp.c index 28394e6..6dd9564 100644 --- a/ekp_c/ekp.c +++ b/ekp_c/ekp.c @@ -620,11 +620,11 @@ static void defun(emacs_env *env, const char *name, */ int emacs_module_init(struct emacs_runtime *runtime) { - if (runtime->size < sizeof(*runtime)) + if ((size_t)runtime->size < sizeof(*runtime)) return 1; emacs_env *env = runtime->get_environment(runtime); - if (env->size < sizeof(*env)) + if ((size_t)env->size < sizeof(*env)) return 2; /* Define functions */ diff --git a/ekp_c/ekp_kp.c b/ekp_c/ekp_kp.c index 88f0883..7ed72e4 100644 --- a/ekp_c/ekp_kp.c +++ b/ekp_c/ekp_kp.c @@ -81,30 +81,6 @@ static inline double compute_demerits(double badness, int32_t penalty, 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 */ diff --git a/ekp_c/ekp_paragraph.c b/ekp_c/ekp_paragraph.c index 44b1e9f..5850556 100644 --- a/ekp_c/ekp_paragraph.c +++ b/ekp_c/ekp_paragraph.c @@ -22,15 +22,6 @@ #define GLUE_CWS 3 /* CJK character space */ /* 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) { unsigned char c = s[0]; @@ -82,15 +73,6 @@ static inline bool is_cjk_punct(uint32_t cp) 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) { 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 */ size_t box_count = 0; size_t pos = 0; - uint8_t prev_type = BOX_SPACE; size_t word_start = 0; bool in_latin_word = false; @@ -212,7 +193,6 @@ ekp_paragraph_t *ekp_para_create(const char *text, size_t len, box_count++; } - prev_type = type; pos += char_len; }