-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Java version of a function that was in the hot path
- Loading branch information
1 parent
84b0dd7
commit 7c4c62b
Showing
2 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/org/rascalmpl/core/library/lang/rascalcore/Performance.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,47 @@ | ||
package org.rascalmpl.core.library.lang.rascalcore; | ||
|
||
import java.util.Objects; | ||
|
||
import io.usethesource.vallang.IBool; | ||
import io.usethesource.vallang.ISourceLocation; | ||
import io.usethesource.vallang.IValueFactory; | ||
|
||
public class Performance { | ||
private final IValueFactory vf; | ||
|
||
public Performance(IValueFactory vf) { | ||
this.vf = vf; | ||
} | ||
|
||
private static boolean isSameFile(ISourceLocation inner, ISourceLocation outer) { | ||
return Objects.equals(inner.getScheme(), outer.getScheme()) | ||
&& Objects.equals(inner.getAuthority(), outer.getAuthority()) | ||
&& Objects.equals(inner.getPath(), outer.getPath()) | ||
&& Objects.equals(inner.getQuery(), outer.getQuery()) | ||
; | ||
} | ||
|
||
public IBool isStrictlyContainedIn2(ISourceLocation inner, ISourceLocation outer) { | ||
if (!isSameFile(inner, outer)) { | ||
return vf.bool(false); | ||
} | ||
// original code would also do full equality, but we don't need that due to the logic in the outer & inner offset compares | ||
if (inner.hasOffsetLength()) { | ||
int innerOffset = inner.getOffset(); | ||
int innerLength = inner.getLength(); | ||
if (outer.hasOffsetLength()) { | ||
int outerOffset = outer.getOffset(); | ||
int outerLength = outer.getLength(); | ||
return vf.bool( | ||
innerOffset == outerOffset && innerOffset + innerLength < outerOffset + outerLength | ||
|| innerOffset > outerOffset && innerOffset + innerLength <= outerOffset + outerLength | ||
); | ||
} | ||
else { | ||
return vf.bool(innerOffset > 0); | ||
} | ||
} | ||
return vf.bool(false); | ||
} | ||
|
||
} |
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