10 * copies or substantial portions of the Software.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18 * SOFTWARE.
19 */
20 package jdk.nashorn.internal.runtime.regexp.joni.ast;
21
22 import jdk.nashorn.internal.runtime.regexp.joni.EncodingHelper;
23 import jdk.nashorn.internal.runtime.regexp.joni.constants.StringType;
24
25 @SuppressWarnings("javadoc")
26 public final class StringNode extends Node implements StringType {
27
28 private static final int NODE_STR_MARGIN = 16;
29 private static final int NODE_STR_BUF_SIZE = 24;
30 public static final StringNode EMPTY = new StringNode(null, Integer.MAX_VALUE, Integer.MAX_VALUE);
31
32 public char[] chars;
33 public int p;
34 public int end;
35
36 public int flag;
37
38 public StringNode() {
39 this.chars = new char[NODE_STR_BUF_SIZE];
40 }
41
42 public StringNode(final char[] chars, final int p, final int end) {
43 this.chars = chars;
44 this.p = p;
45 this.end = end;
46 setShared();
47 }
48
49 public StringNode(final char c) {
50 this();
51 chars[end++] = c;
52 }
53
54 /* Ensure there is ahead bytes available in node's buffer
55 * (assumes that the node is not shared)
56 */
57 public void ensure(final int ahead) {
58 final int len = (end - p) + ahead;
59 if (len >= chars.length) {
60 final char[] tmp = new char[len + NODE_STR_MARGIN];
61 System.arraycopy(chars, p, tmp, 0, end - p);
62 chars = tmp;
63 }
64 }
65
66 /* COW and/or ensure there is ahead bytes available in node's buffer
67 */
68 private void modifyEnsure(final int ahead) {
69 if (isShared()) {
70 final int len = (end - p) + ahead;
71 final char[] tmp = new char[len + NODE_STR_MARGIN];
|
10 * copies or substantial portions of the Software.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18 * SOFTWARE.
19 */
20 package jdk.nashorn.internal.runtime.regexp.joni.ast;
21
22 import jdk.nashorn.internal.runtime.regexp.joni.EncodingHelper;
23 import jdk.nashorn.internal.runtime.regexp.joni.constants.StringType;
24
25 @SuppressWarnings("javadoc")
26 public final class StringNode extends Node implements StringType {
27
28 private static final int NODE_STR_MARGIN = 16;
29 private static final int NODE_STR_BUF_SIZE = 24;
30
31 public char[] chars;
32 public int p;
33 public int end;
34
35 public int flag;
36
37 public StringNode() {
38 this(NODE_STR_BUF_SIZE);
39 }
40
41 private StringNode(int size) {
42 this.chars = new char[size];
43 this.p = 0;
44 this.end = 0;
45 }
46
47 public StringNode(final char[] chars, final int p, final int end) {
48 this.chars = chars;
49 this.p = p;
50 this.end = end;
51 setShared();
52 }
53
54 public StringNode(final char c) {
55 this();
56 chars[end++] = c;
57 }
58
59 /**
60 * Create a new empty StringNode.
61 */
62 public static StringNode createEmpty() {
63 return new StringNode(0);
64 }
65
66 /* Ensure there is ahead bytes available in node's buffer
67 * (assumes that the node is not shared)
68 */
69 public void ensure(final int ahead) {
70 final int len = (end - p) + ahead;
71 if (len >= chars.length) {
72 final char[] tmp = new char[len + NODE_STR_MARGIN];
73 System.arraycopy(chars, p, tmp, 0, end - p);
74 chars = tmp;
75 }
76 }
77
78 /* COW and/or ensure there is ahead bytes available in node's buffer
79 */
80 private void modifyEnsure(final int ahead) {
81 if (isShared()) {
82 final int len = (end - p) + ahead;
83 final char[] tmp = new char[len + NODE_STR_MARGIN];
|