forked from pfalcon/re1.5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sub.c
55 lines (47 loc) · 707 Bytes
/
sub.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2007-2009 Russ Cox. All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
#include "re1.5.h"
Sub *freesub;
Sub*
newsub(int n)
{
Sub *s;
s = freesub;
if(s != nil)
freesub = (Sub*)s->sub[0];
else
s = mal(sizeof *s);
s->nsub = n;
s->ref = 1;
return s;
}
Sub*
incref(Sub *s)
{
s->ref++;
return s;
}
Sub*
update(Sub *s, int i, const char *p)
{
Sub *s1;
int j;
if(s->ref > 1) {
s1 = newsub(s->nsub);
for(j=0; j<s->nsub; j++)
s1->sub[j] = s->sub[j];
s->ref--;
s = s1;
}
s->sub[i] = p;
return s;
}
void
decref(Sub *s)
{
if(--s->ref == 0) {
s->sub[0] = (char*)freesub;
freesub = s;
}
}