size_offsets = num_subpats * 3;
/*
- * Build a mapping from subpattern numbers to their names. We will always
- * allocate the table, even though there may be no named subpatterns. This
- * avoids somewhat more complicated logic in the inner loops.
+ * Build a mapping from subpattern numbers to their names. We will
+ * allocate the table only if there are any named subpatterns.
*/
- subpat_names = make_subpats_table(num_subpats, pce TSRMLS_CC);
- if (!subpat_names) {
- RETURN_FALSE;
+ subpat_names = NULL;
+ if (pce->name_count > 0) {
+ subpat_names = make_subpats_table(num_subpats, pce TSRMLS_CC);
+ if (!subpat_names) {
+ RETURN_FALSE;
+ }
}
- offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0);
+ if (size_offsets <= 32) {
+ offsets = (int *)do_alloca(size_offsets * sizeof(int), use_heap);
+ } else {
+ offsets = (int *)safe_emalloc(size_offsets, sizeof(int), 0);
+ }
-
+ memset(offsets, 0, size_offsets*sizeof(int));
/* Allocate match sets array and initialize the values. */
if (global && subpats && subpats_order == PREG_PATTERN_ORDER) {
- match_sets = (zval **)safe_emalloc(num_subpats, sizeof(zval *), 0);
+ match_sets = (zval *)safe_emalloc(num_subpats, sizeof(zval), 0);
for (i=0; i<num_subpats; i++) {
- ALLOC_ZVAL(match_sets[i]);
- array_init(match_sets[i]);
- INIT_PZVAL(match_sets[i]);
+ array_init(&match_sets[i]);
}
}