Skip to content
Snippets Groups Projects
Commit 957c22be authored by Lukas Stadler's avatar Lukas Stadler
Browse files

more profiling in vector access, avoid costly division if possible

parent 1e921ff9
Branches
No related tags found
No related merge requests found
......@@ -59,6 +59,9 @@ final class CachedReplaceVectorNode extends CachedVectorNode {
private final BranchProfile resizeProfile = BranchProfile.create();
private final BranchProfile sharedProfile = BranchProfile.create();
private final ConditionProfile valueLengthOneProfile = ConditionProfile.createBinaryProfile();
private final ConditionProfile emptyReplacementProfile = ConditionProfile.createBinaryProfile();
private final RType valueType;
private final RType castType;
private final boolean updatePositionNames;
......@@ -190,12 +193,12 @@ final class CachedReplaceVectorNode extends CachedVectorNode {
}
int replacementLength = positionsCheckNode.getSelectedPositionsCount(positionProfiles);
if (replacementLength == 0) {
if (emptyReplacementProfile.profile(replacementLength == 0)) {
/* Nothing to modify */
return vector;
}
if (valueLength != 1) {
if (valueLengthOneProfile.profile(valueLength != 1)) {
verifyValueLength(positionProfiles, valueLength);
}
......@@ -227,7 +230,7 @@ final class CachedReplaceVectorNode extends CachedVectorNode {
* Interestingly we always need to provide not NOT_MULTIPLE_REPLACEMENT error messages
* for multi-dimensional deletes.
*/
if ((this.numberOfDimensions > 1 && isNullValue()) || replacementLength % valueLength != 0) {
if ((this.numberOfDimensions > 1 && isNullValue()) || (replacementLength != valueLength && replacementLength % valueLength != 0)) {
if (this.numberOfDimensions > 1) {
errorBranch.enter();
throw RError.error(this, RError.Message.NOT_MULTIPLE_REPLACEMENT);
......
......@@ -73,7 +73,7 @@ abstract class PositionCheckSubsetNode extends PositionCheckNode {
}
protected static boolean isMultiplesOf(int a, int b) {
return b != 0 && a % b == 0;
return b != 0 && (a == b || a % b == 0);
}
@Specialization(contains = "doLogicalMultiplesInBounds")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment