Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc optimization #37

Merged
merged 29 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/main/java/ch/digitalfondue/jfiveparse/AttributeNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ public class AttributeNode {

String name;
String originalName;
String value;

private String value;
private ResizableCharBuilder valueBuilder;

//
String prefix;
Expand All @@ -36,8 +38,9 @@ public AttributeNode(String name, String value) {
this.value = value;
}

AttributeNode(String name, String originalName, String value, int attributeQuoteType) {
this(name, value);
AttributeNode(String name, String originalName, ResizableCharBuilder value, int attributeQuoteType) {
this.name = name;
this.valueBuilder = value;
this.originalName = originalName;
this.attributeQuoteType = attributeQuoteType;
}
Expand All @@ -46,6 +49,7 @@ public AttributeNode(String name, String value) {
this.name = a.name;
this.originalName = a.originalName;
this.value = a.value;
this.valueBuilder = a.valueBuilder;
this.prefix = a.prefix;
this.namespace = a.namespace;
this.attributeQuoteType = a.attributeQuoteType;
Expand All @@ -58,10 +62,15 @@ public AttributeNode(String name, String value, String prefix, String namespace)
}

public String getValue() {
if (value == null && valueBuilder != null) {
value = valueBuilder.asString();
valueBuilder = null;
}
return value;
}

public void setValue(String value) {
this.valueBuilder = null;
this.value = value;
}

Expand All @@ -79,7 +88,7 @@ public String getName() {

@Override
public int hashCode() {
return Objects.hash(name, value, prefix, namespace);
return Objects.hash(name, getValue(), prefix, namespace);
}

@Override
Expand All @@ -91,7 +100,7 @@ public boolean equals(Object obj) {
if (obj instanceof AttributeNode) {
AttributeNode other = (AttributeNode) obj;
return name.equals(other.name) && //
value.equals(other.value) && //
getValue().equals(other.getValue()) && //
Objects.equals(prefix, other.prefix) && //
Objects.equals(namespace, other.namespace);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/digitalfondue/jfiveparse/Attributes.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ public Iterator<AttributeNode> iterator() {
}

public String getNamedItem(String name) {
return attributes != null && attributes.containsKey(name) ? attributes.get(name).value : null;
return attributes != null && attributes.containsKey(name) ? attributes.get(name).getValue() : null;
}
}
10 changes: 10 additions & 0 deletions src/main/java/ch/digitalfondue/jfiveparse/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,33 @@
*/
public class Comment extends Node {

ResizableCharBuilder dataBuilder;
private String data;

public Comment(String data) {
this.data = data;
}

Comment(ResizableCharBuilder dataBuilder) {
this.dataBuilder = dataBuilder;
}

@Override
public byte getNodeType() {
return COMMENT_NODE;
}

public String getData() {
if (data == null && dataBuilder != null) {
data = dataBuilder.asString();
dataBuilder = null;
}
return data;
}

public void setData(String data) {
this.data = data;
this.dataBuilder = null;
}

/**
Expand Down
Loading