diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/fastpaths/IsElementFastPath.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/fastpaths/IsElementFastPath.java index c211bb753ea774dc4e87c6f5e7e69554bbd9067b..b4b9c2b17c39951b94199db27ce9e3f712a5dbaa 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/fastpaths/IsElementFastPath.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/fastpaths/IsElementFastPath.java @@ -57,7 +57,7 @@ public abstract class IsElementFastPath extends RFastPathNode { return RRuntime.LOGICAL_FALSE; } - @Specialization(replaces = "iselementOneCachedString") + @Specialization(guards = "elIn.getLength() == 1", replaces = "iselementOneCachedString") protected Byte iselementOne(RAbstractStringVector elIn, RAbstractStringVector setIn, @Cached("create()") BranchProfile trueProfile, @Cached("create()") BranchProfile falseProfile) { diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestIsElement.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestIsElement.java new file mode 100644 index 0000000000000000000000000000000000000000..ec27ac1989d18ed27bcb3aa637022e37904f87e4 --- /dev/null +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestIsElement.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.r.test.library.base; + +import org.junit.Test; + +import com.oracle.truffle.r.test.TestBase; + +public class TestIsElement extends TestBase { + + @Test + public void testIsElement() { + assertEval("{ is.element(c('a', 'b', 'b'), 'b') }"); + assertEval("{ is.element('b', c('a', 'b', 'b')) }"); + assertEval("{ is.element(paste0('a', 1:10), 'a1') }"); + assertEval("{ is.element(paste0('a', 1:10), 'a0') }"); + assertEval("{ is.element(paste0('a', c(1:10, rep(11,2))), 'a11') }"); + assertEval("{ is.element(c(1:10,rep(11,10)), 1) }"); + assertEval("{ is.element(c(1:10,rep(11,10)), 11) }"); + assertEval("{ is.element(c(1:10,rep(11,10)), c(1:10,rep(11,10))) }"); + } +}