-
Notifications
You must be signed in to change notification settings - Fork 744
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make cache sharable between type descriptors
- Loading branch information
1 parent
8f70ddf
commit dca84d0
Showing
9 changed files
with
109 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...allerina-runtime/src/main/java/io/ballerina/runtime/api/types/semtype/TypeCheckCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.ballerina.runtime.api.types.semtype; | ||
|
||
import io.ballerina.runtime.api.types.Type; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.WeakHashMap; | ||
|
||
public class TypeCheckCache<T extends Type> { | ||
|
||
private final Map<T, Boolean> cachedResults = new WeakHashMap<>(); | ||
private final T owner; | ||
|
||
public TypeCheckCache(T owner) { | ||
this.owner = owner; | ||
} | ||
|
||
public Optional<Boolean> cachedTypeCheckResult(T other) { | ||
if (other.equals(owner)) { | ||
return Optional.of(true); | ||
} | ||
return Optional.ofNullable(cachedResults.get(other)); | ||
} | ||
|
||
public void cacheTypeCheckResult(T other, boolean result) { | ||
cachedResults.put(other, result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.