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

Function re_node_set_merge

compat/regex/regex_internal.c:1205–1285  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1203
1204/* Calculate the union set of the sets DEST and SRC. And store it to
1205 DEST. Return value indicate the error code or REG_NOERROR if succeeded. */
1206
1207static reg_errcode_t
1208internal_function
1209re_node_set_merge (re_node_set *dest, const re_node_set *src)
1210{
1211 int is, id, sbase, delta;
1212 if (src == NULL || src->nelem == 0)
1213 return REG_NOERROR;
1214 if (dest->alloc < 2 * src->nelem + dest->nelem)
1215 {
1216 int new_alloc = 2 * (src->nelem + dest->alloc);
1217 int *new_buffer = re_realloc (dest->elems, int, new_alloc);
1218 if (BE (new_buffer == NULL, 0))
1219 return REG_ESPACE;
1220 dest->elems = new_buffer;
1221 dest->alloc = new_alloc;
1222 }
1223
1224 if (BE (dest->nelem == 0, 0))
1225 {
1226 dest->nelem = src->nelem;
1227 memcpy (dest->elems, src->elems, src->nelem * sizeof (int));
1228 return REG_NOERROR;
1229 }
1230
1231 /* Copy into the top of DEST the items of SRC that are not
1232 found in DEST. Maybe we could binary search in DEST? */
1233 for (sbase = dest->nelem + 2 * src->nelem,
1234 is = src->nelem - 1, id = dest->nelem - 1; is >= 0 && id >= 0; )
1235 {
1236 if (dest->elems[id] == src->elems[is])
1237 {
1238 is--;
1239 id--;
1240 }
1241 else if (dest->elems[id] < src->elems[is])
1242 dest->elems[--sbase] = src->elems[is--];
1243 else /* if (dest->elems[id] > src->elems[is]) */
1244 --id;
1245 }
1246
1247 if (is >= 0)
1248 {
1249 /* If DEST is exhausted, the remaining items of SRC must be unique. */
1250 sbase -= is + 1;
1251 memcpy (dest->elems + sbase, src->elems, (is + 1) * sizeof (int));
1252 }
1253
1254 id = dest->nelem - 1;
1255 is = dest->nelem + 2 * src->nelem - 1;
1256 delta = is - sbase + 1;
1257 if (delta == 0)
1258 return REG_NOERROR;
1259
1260 /* Now copy. When DELTA becomes zero, the remaining
1261 DEST elements are already in place. */
1262 dest->nelem += delta;

Callers 8

add_epsilon_src_nodesFunction · 0.85
transit_state_sbFunction · 0.85
internal_functionFunction · 0.85
check_arrival_expand_eclFunction · 0.85
expand_bkref_cacheFunction · 0.85
create_initial_stateFunction · 0.85
calc_eclosure_iterFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected