Skip to content

Commit

Permalink
[refactor] dry-out JRuby's DocumentFragment#add_child impl
Browse files Browse the repository at this point in the history
  • Loading branch information
kares committed Oct 16, 2019
1 parent f41f618 commit 6129285
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions ext/java/nokogiri/XmlDocumentFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
*/
@JRubyClass(name="Nokogiri::XML::DocumentFragment", parent="Nokogiri::XML::Node")
public class XmlDocumentFragment extends XmlNode {
private XmlElement fragmentContext = null;

private XmlElement fragmentContext;

public XmlDocumentFragment(Ruby ruby) {
this(ruby, getNokogiriClass(ruby, "Nokogiri::XML::DocumentFragment"));
Expand Down Expand Up @@ -177,20 +178,15 @@ public XmlElement getFragmentContext() {
return fragmentContext;
}

//@Override
public void add_child(ThreadContext context, XmlNode child) {
// Some magic for DocumentFragment

Ruby ruby = context.getRuntime();
XmlNodeSet children = (XmlNodeSet) child.children(context);

long length = children.length();

RubyArray childrenArray = children.convertToArray();

if(length != 0) {
for(int i = 0; i < length; i++) {
XmlNode item = (XmlNode) ((XmlNode) childrenArray.aref(ruby.newFixnum(i))).dup_implementation(context, true);
int length = children.length();
if (length != 0) {
for (int i = 0; i < length; i++) {
XmlNode item = ((XmlNode) children.nodes[i]).cloneImpl(true);
add_child(context, item);
}
}
Expand Down

0 comments on commit 6129285

Please sign in to comment.