Skip to content

Commit

Permalink
Move clear volatile impl to AbstractTreeElement impl and more PR feed…
Browse files Browse the repository at this point in the history
…back
  • Loading branch information
shubham1g5 committed Jul 4, 2024
1 parent 3583190 commit aba181b
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ public TreeReference getRef() {

@Override
public void clearVolatiles() {
// we should also clear the other cache implementation in this class in future
ref = null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/javarosa/core/model/FormDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public FormIndex deleteRepeat(FormIndex index) {

reduceTreeSiblingMultiplicities(parentElement, deleteElement);

this.getMainInstance().cleanCache(parentElement);
this.getMainInstance().cleanCache();

triggerTriggerables(deleteRef);
return newIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,16 @@ public TreeReference getRef() {
@Override
public void clearVolatiles() {
refCache = null;
if (children != null) {
for (T child : children) {
child.clearVolatiles();
}
}
if (attributes != null) {
for (T attribute : attributes) {
attribute.clearVolatiles();
}
}
}

@Override
Expand Down
23 changes: 2 additions & 21 deletions src/main/java/org/javarosa/core/model/instance/DataInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,30 +289,11 @@ public void setCacheHost(CacheHost cacheHost) {
this.mCacheHost = cacheHost;
}

public void cleanCache() {
cleanCache(getBase());
}

/**
* Cleans reference caches maintained by the instance and TreeElements contained in the contextNode
* @param contextNode Parent node inside the scope of which we clear the TreeElement volatiles
*/
public void cleanCache(AbstractTreeElement<T> contextNode) {
public void cleanCache() {
referenceCache.clear();
cleanTreeElementCache(contextNode);
}

/**
* Loops through the node and it's children and clears their volatiles
* @param contextNode Parent node inside the scope of which we clear the TreeElement volatiles
*/
private void cleanTreeElementCache(AbstractTreeElement<T> contextNode) {
if (contextNode == null) {
return;
}
contextNode.clearVolatiles();
for (int i = 0; i < contextNode.getNumChildren(); i++) {
cleanTreeElementCache(contextNode.getChildAt(i));
}
getBase().clearVolatiles();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ public TreeReference getRef() {

@Override
public void clearVolatiles() {
// nothing to clear
if (child != null) {
child.clearVolatiles();
}
}

@Override
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/javarosa/core/model/instance/TreeElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,16 @@ public String getNamespace() {
@Override
public void clearVolatiles() {
refCache[0] = null;
if (children != null) {
for (TreeElement child : children) {
child.clearVolatiles();
}
}
if (attributes != null) {
for (TreeElement attribute : attributes) {
attribute.clearVolatiles();
}
}
}

public void setNamespace(String namespace) {
Expand Down

0 comments on commit aba181b

Please sign in to comment.