| 1532 | Note: - We assume NULL as the invalid state, then it is possible that |
| 1533 | return value is NULL and ERR is REG_NOERROR. |
| 1534 | - We never return non-NULL value in case of any errors, it is for |
| 1535 | optimization. */ |
| 1536 | |
| 1537 | static re_dfastate_t * |
| 1538 | internal_function |
| 1539 | re_acquire_state_context (reg_errcode_t *err, const re_dfa_t *dfa, |
| 1540 | const re_node_set *nodes, unsigned int context) |
| 1541 | { |
| 1542 | unsigned int hash; |
| 1543 | re_dfastate_t *new_state; |
| 1544 | struct re_state_table_entry *spot; |
| 1545 | int i; |
| 1546 | if (nodes->nelem == 0) |
| 1547 | { |
| 1548 | *err = REG_NOERROR; |
| 1549 | return NULL; |
| 1550 | } |
| 1551 | hash = calc_state_hash (nodes, context); |
| 1552 | spot = dfa->state_table + (hash & dfa->state_hash_mask); |
| 1553 | |
| 1554 | for (i = 0 ; i < spot->num ; i++) |
| 1555 | { |
| 1556 | re_dfastate_t *state = spot->array[i]; |
| 1557 | if (state->hash == hash |
| 1558 | && state->context == context |
| 1559 | && re_node_set_compare (state->entrance_nodes, nodes)) |
| 1560 | return state; |
| 1561 | } |
| 1562 | /* There are no appropriate state in `dfa', create the new one. */ |
| 1563 | new_state = create_cd_newstate (dfa, nodes, context, hash); |
| 1564 | if (BE (new_state == NULL, 0)) |
| 1565 | *err = REG_ESPACE; |
| 1566 | |
| 1567 | return new_state; |
| 1568 | } |
no test coverage detected