From f1b49b7bb9118e336b8ce2ebe5a12af5881f83c3 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 22 May 2014 05:02:15 +0000 Subject: constify character property tables * enc/jis/props.kwd: constify character property tables of JIS based encodings by perfect hash. * enc/euc_jp.c, enc/shift_jis.c: use character property functions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46039 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- enc/shift_jis.c | 42 +++++------------------------------------- 1 file changed, 5 insertions(+), 37 deletions(-) (limited to 'enc/shift_jis.c') diff --git a/enc/shift_jis.c b/enc/shift_jis.c index 5f5a802874..530415b87c 100644 --- a/enc/shift_jis.c +++ b/enc/shift_jis.c @@ -433,12 +433,6 @@ is_allowed_reverse_match(const UChar* s, const UChar* end, OnigEncoding enc ARG_ } -static int PropertyInited = 0; -static const OnigCodePoint** PropertyList; -static int PropertyListNum; -static int PropertyListSize; -static hash_table_type* PropertyNameTable; - static const OnigCodePoint CR_Hiragana[] = { 1, 0x829f, 0x82f1 @@ -493,41 +487,19 @@ static const OnigCodePoint CR_Cyrillic[] = { 0x8480, 0x8491, }; /* CR_Cyrillic */ -static int -init_property_list(void) -{ - int r; - - PROPERTY_LIST_ADD_PROP("hiragana", CR_Hiragana); - PROPERTY_LIST_ADD_PROP("katakana", CR_Katakana); - PROPERTY_LIST_ADD_PROP("han", CR_Han); - PROPERTY_LIST_ADD_PROP("latin", CR_Latin); - PROPERTY_LIST_ADD_PROP("greek", CR_Greek); - PROPERTY_LIST_ADD_PROP("cyrillic", CR_Cyrillic); - PropertyInited = 1; - - end: - return r; -} +#include "enc/jis/props.h" static int property_name_to_ctype(OnigEncoding enc, UChar* p, UChar* end) { - hash_data_type ctype; - UChar *s, *e; - - PROPERTY_LIST_INIT_CHECK; + UChar *s = p, *e = end; + const struct enc_property *prop = onig_jis_property((const char *)s, (unsigned int)(e-s)); - s = e = ALLOCA_N(UChar, end-p+1); - for (; p < end; p++) { - *e++ = ONIGENC_ASCII_CODE_TO_LOWER_CASE(*p); - } - - if (onig_st_lookup_strend(PropertyNameTable, s, e, &ctype) == 0) { + if (!prop) { return onigenc_minimum_property_name_to_ctype(enc, s, e); } - return (int )ctype; + return (int)prop->ctype; } static int @@ -543,8 +515,6 @@ is_code_ctype(OnigCodePoint code, unsigned int ctype, OnigEncoding enc) } } else { - PROPERTY_LIST_INIT_CHECK; - ctype -= (ONIGENC_MAX_STD_CTYPE + 1); if (ctype >= (unsigned int )PropertyListNum) return ONIGERR_TYPE_BUG; @@ -565,8 +535,6 @@ get_ctype_code_range(OnigCtype ctype, OnigCodePoint* sb_out, else { *sb_out = 0x80; - PROPERTY_LIST_INIT_CHECK; - ctype -= (ONIGENC_MAX_STD_CTYPE + 1); if (ctype >= (OnigCtype )PropertyListNum) return ONIGERR_TYPE_BUG; -- cgit v1.2.3