Skip to content

Commit

Permalink
use `new' instead of the allocator
Browse files Browse the repository at this point in the history
some minor changes as well for readability
  • Loading branch information
jvshahid committed Dec 9, 2015
1 parent 743058a commit d81ce3b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions ext/java/nokogiri/XmlNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -1085,20 +1085,21 @@ public IRubyObject namespace(ThreadContext context) {
Ruby runtime = context.getRuntime();
if (doc instanceof HtmlDocument) return runtime.getNil();
NokogiriNamespaceCache nsCache = NokogiriHelpers.getNamespaceCacheFormNode(node);
String prefix = node.getPrefix();
String namespaceURI = node.getNamespaceURI();
if (namespaceURI == null || namespaceURI == "") {
return runtime.getNil();
}

String prefix = node.getPrefix();
XmlNamespace namespace = nsCache.get(prefix == null ? "" : prefix, namespaceURI);
if (namespace == null || namespace.isEmpty()) {
// if it's not in the cache, create an unowned, uncached namespace and
// return that. XmlReader can't insert namespaces into the cache, so
// this is necessary for XmlReader to work correctly.
namespace =
(XmlNamespace) NokogiriService.XML_NAMESPACE_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Namespace"));
namespace.init(null, RubyString.newString(runtime, prefix), RubyString.newString(runtime, namespaceURI), doc);
namespace = new XmlNamespace(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Namespace"));
IRubyObject rubyPrefix = NokogiriHelpers.stringOrNil(runtime, prefix);
IRubyObject rubyUri = NokogiriHelpers.stringOrNil(runtime, namespaceURI);
namespace.init(null, rubyPrefix, rubyUri, doc);
}

return namespace;
Expand Down

0 comments on commit d81ce3b

Please sign in to comment.