MCPcopy Create free account
hub / github.com/git/git / optimize_utf8

Function optimize_utf8

compat/regex/regcomp.c:1089–1153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1087}
1088
1089
1090#ifdef RE_ENABLE_I18N
1091/* If it is possible to do searching in single byte encoding instead of UTF-8
1092 to speed things up, set dfa->mb_cur_max to 1, clear is_utf8 and change
1093 DFA nodes where needed. */
1094
1095static void
1096optimize_utf8 (re_dfa_t *dfa)
1097{
1098 int node, i, mb_chars = 0, has_period = 0;
1099
1100 for (node = 0; node < dfa->nodes_len; ++node)
1101 switch (dfa->nodes[node].type)
1102 {
1103 case CHARACTER:
1104 if (dfa->nodes[node].opr.c >= 0x80)
1105 mb_chars = 1;
1106 break;
1107 case ANCHOR:
1108 switch (dfa->nodes[node].opr.ctx_type)
1109 {
1110 case LINE_FIRST:
1111 case LINE_LAST:
1112 case BUF_FIRST:
1113 case BUF_LAST:
1114 break;
1115 default:
1116 /* Word anchors etc. cannot be handled. It's okay to test
1117 opr.ctx_type since constraints (for all DFA nodes) are
1118 created by ORing one or more opr.ctx_type values. */
1119 return;
1120 }
1121 break;
1122 case OP_PERIOD:
1123 has_period = 1;
1124 break;
1125 case OP_BACK_REF:
1126 case OP_ALT:
1127 case END_OF_RE:
1128 case OP_DUP_ASTERISK:
1129 case OP_OPEN_SUBEXP:
1130 case OP_CLOSE_SUBEXP:
1131 break;
1132 case COMPLEX_BRACKET:
1133 return;
1134 case SIMPLE_BRACKET:
1135 /* Just double check. The non-ASCII range starts at 0x80. */
1136 assert (0x80 % BITSET_WORD_BITS == 0);
1137 for (i = 0x80 / BITSET_WORD_BITS; i < BITSET_WORDS; ++i)
1138 if (dfa->nodes[node].opr.sbcset[i])
1139 return;
1140 break;
1141 default:
1142 abort ();
1143 }
1144
1145 if (mb_chars || has_period)
1146 for (node = 0; node < dfa->nodes_len; ++node)

Callers 1

re_compile_internalFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected