From d81ce3b064a7048df14b645141bf1fa150b4c20f Mon Sep 17 00:00:00 2001 From: John Shahid Date: Wed, 9 Dec 2015 06:42:22 -0500 Subject: [PATCH] use `new' instead of the allocator some minor changes as well for readability --- ext/java/nokogiri/XmlNode.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ext/java/nokogiri/XmlNode.java b/ext/java/nokogiri/XmlNode.java index 8b5673a3cc..fa0fd2548a 100644 --- a/ext/java/nokogiri/XmlNode.java +++ b/ext/java/nokogiri/XmlNode.java @@ -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;