Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
QueryR
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julien Lopez
QueryR
Commits
82e3fd41
Commit
82e3fd41
authored
7 years ago
by
Florian Angerer
Browse files
Options
Downloads
Patches
Plain Diff
Using RStringSequence in builtin 'paste'.
parent
644a0c05
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Paste.java
+38
-5
38 additions, 5 deletions
...in/src/com/oracle/truffle/r/nodes/builtin/base/Paste.java
with
38 additions
and
5 deletions
com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Paste.java
+
38
−
5
View file @
82e3fd41
...
...
@@ -45,8 +45,11 @@ import com.oracle.truffle.r.nodes.unary.CastNode;
import
com.oracle.truffle.r.runtime.RError.Message
;
import
com.oracle.truffle.r.runtime.builtins.RBuiltin
;
import
com.oracle.truffle.r.runtime.data.RDataFactory
;
import
com.oracle.truffle.r.runtime.data.RIntSequence
;
import
com.oracle.truffle.r.runtime.data.RList
;
import
com.oracle.truffle.r.runtime.data.RNull
;
import
com.oracle.truffle.r.runtime.data.RScalar
;
import
com.oracle.truffle.r.runtime.data.RStringSequence
;
import
com.oracle.truffle.r.runtime.data.RStringVector
;
import
com.oracle.truffle.r.runtime.data.model.RAbstractListVector
;
import
com.oracle.truffle.r.runtime.data.model.RAbstractStringVector
;
...
...
@@ -101,14 +104,18 @@ public abstract class Paste extends RBuiltinNode.Arg3 {
}
@Specialization
protected
RStringVector
pasteListNullSep
(
VirtualFrame
frame
,
RAbstractListVector
values
,
String
sep
,
@SuppressWarnings
(
"unused"
)
RNull
collapse
)
{
protected
R
Abstract
StringVector
pasteListNullSep
(
VirtualFrame
frame
,
RAbstractListVector
values
,
String
sep
,
@SuppressWarnings
(
"unused"
)
RNull
collapse
)
{
int
length
=
lengthProfile
.
profile
(
values
.
getLength
());
if
(
hasNonNullElements
(
values
,
length
))
{
String
[]
result
=
pasteListElements
(
frame
,
values
,
sep
,
length
);
if
(
result
==
ONE_EMPTY_STRING
)
{
return
RDataFactory
.
createEmptyStringVector
();
if
(
isStringSequence
(
values
,
length
))
{
return
createStringSequence
(
values
,
length
,
sep
);
}
else
{
return
RDataFactory
.
createStringVector
(
result
,
RDataFactory
.
COMPLETE_VECTOR
);
String
[]
result
=
pasteListElements
(
frame
,
values
,
sep
,
length
);
if
(
result
==
ONE_EMPTY_STRING
)
{
return
RDataFactory
.
createEmptyStringVector
();
}
else
{
return
RDataFactory
.
createStringVector
(
result
,
RDataFactory
.
COMPLETE_VECTOR
);
}
}
}
else
{
return
RDataFactory
.
createEmptyStringVector
();
...
...
@@ -253,4 +260,30 @@ public abstract class Paste extends RBuiltinNode.Arg3 {
}
return
asCharacterNode
;
}
/**
* Tests for pattern = { stringScalar } intSequence.
*/
private
static
boolean
isStringSequence
(
RAbstractListVector
values
,
int
length
)
{
int
i
=
0
;
while
(
i
<
length
&&
isScalar
(
values
.
getDataAt
(
i
)))
{
i
++;
}
return
i
<
length
&&
values
.
getDataAt
(
i
)
instanceof
RIntSequence
;
}
private
static
boolean
isScalar
(
Object
dataAt
)
{
return
dataAt
instanceof
RScalar
||
dataAt
instanceof
String
||
dataAt
instanceof
Double
||
dataAt
instanceof
Integer
||
dataAt
instanceof
Byte
;
}
private
static
RStringSequence
createStringSequence
(
RAbstractListVector
values
,
int
length
,
String
sep
)
{
assert
isStringSequence
(
values
,
length
);
StringBuilder
sb
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
values
.
getLength
()
-
1
;
i
++)
{
sb
.
append
(
values
.
getDataAt
(
i
)).
append
(
sep
);
}
RIntSequence
seq
=
(
RIntSequence
)
values
.
getDataAt
(
length
-
1
);
return
RDataFactory
.
createStringSequence
(
sb
.
toString
(),
seq
.
getStart
(),
seq
.
getStride
(),
seq
.
getLength
());
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment