Skip to content

Commit 5cd5170

Browse files
committed
Release 1.1.11:
* Performance improvements from @jperville.
2 parents f2a9160 + ac96017 commit 5cd5170

File tree

10 files changed

+43
-18
lines changed

10 files changed

+43
-18
lines changed

.fasterer.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
speedups:
2+
parallel_assignment: false
3+
rescue_vs_respond_to: true
4+
module_eval: true
5+
shuffle_first_vs_sample: true
6+
for_loop_vs_each: true
7+
each_with_index_vs_while: false
8+
map_flatten_vs_flat_map: true
9+
reverse_each_vs_reverse_each: true
10+
select_first_vs_detect: true
11+
sort_vs_sort_by: true
12+
fetch_with_argument_vs_block: true
13+
keys_each_vs_each_key: true
14+
hash_merge_bang_vs_hash_brackets: true
15+
block_vs_symbol_to_proc: true
16+
proc_call_vs_yield: true
17+
gsub_vs_tr: true
18+
select_last_vs_reverse_detect: true
19+
getter_vs_attr_reader: false
20+
setter_vs_attr_writer: false
21+
22+
exclude_paths:
23+
- 'vendor/**/*.rb'
24+
- 'spec/**/*.rb'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
/spec.pdf
77
/pkg/
88
/.rbx/
9+
/.bundle/
910
Gemfile.lock

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ gem 'jsonlint', git: "git://github.com/dougbarth/jsonlint.git", platform
88
group :development do
99
gem 'rdf-turtle', git: "git://github.com/ruby-rdf/rdf-turtle.git", branch: "develop"
1010
gem 'rdf-trig', git: "git://github.com/ruby-rdf/rdf-trig.git", branch: "develop"
11+
gem 'fasterer'
1112
end
1213

1314
group :development, :test do

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.10
1+
1.1.11

lib/json/ld/api.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class API
8787
# @yieldparam [API]
8888
# @raise [JsonLdError]
8989
def initialize(input, context, options = {}, &block)
90-
@options = {compactArrays: true, rename_bnodes: true}.merge(options)
90+
@options = {compactArrays: true, rename_bnodes: true}.merge!(options)
9191
@options[:validate] = true if @options[:processingMode] == "json-ld-1.0"
9292
@options[:documentLoader] ||= self.class.method(:documentLoader)
9393
@namer = options[:unique_bnodes] ? BlankNodeUniqer.new : (@options[:rename_bnodes] ? BlankNodeNamer.new("b") : BlankNodeMapper.new)
@@ -98,7 +98,7 @@ def initialize(input, context, options = {}, &block)
9898
@value = case input
9999
when Array, Hash then input.dup
100100
when IO, StringIO
101-
@options = {base: input.base_uri}.merge(@options) if input.respond_to?(:base_uri)
101+
@options = {base: input.base_uri}.merge!(@options) if input.respond_to?(:base_uri)
102102

103103
# if input impelements #links, attempt to get a contextUrl from that link
104104
content_type = input.respond_to?(:content_type) ? input.content_type : "application/json"
@@ -113,7 +113,7 @@ def initialize(input, context, options = {}, &block)
113113
when String
114114
remote_doc = @options[:documentLoader].call(input, @options)
115115

116-
@options = {base: remote_doc.documentUrl}.merge(@options)
116+
@options = {base: remote_doc.documentUrl}.merge!(@options)
117117
context_ref = remote_doc.contextUrl
118118

119119
case remote_doc.document
@@ -322,7 +322,7 @@ def self.frame(input, frame, options = {})
322322
requireAll: true,
323323
omitDefault: false,
324324
documentLoader: method(:documentLoader)
325-
}.merge(options)
325+
}.merge!(options)
326326

327327
framing_state = {
328328
graphs: {'@default' => {}, '@merged' => {}},
@@ -471,7 +471,7 @@ def self.toRdf(input, options = {}, &block)
471471
# @return [Object, Hash]
472472
# If a block is given, the result of evaluating the block is returned, otherwise, the expanded JSON-LD document
473473
def self.fromRdf(input, options = {}, &block)
474-
options = {useNativeTypes: false}.merge(options)
474+
options = {useNativeTypes: false}.merge!(options)
475475
result = nil
476476

477477
API.new(nil, nil, options) do |api|

lib/json/ld/compact.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def compact(element, property = nil)
4646
inside_reverse = property == '@reverse'
4747
result = {}
4848

49-
element.keys.each do |expanded_property|
49+
element.each_key do |expanded_property|
5050
expanded_value = element[expanded_property]
5151
debug("") {"#{expanded_property}: #{expanded_value.inspect}"}
5252

lib/json/ld/context.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ def parse(local_context, remote_contexts = [])
337337
defined = {}
338338
# For each key-value pair in context invoke the Create Term Definition subalgorithm, passing result for active context, context for local context, key, and defined
339339
depth do
340-
context.keys.each do |key|
340+
context.each_key do |key|
341341
result.create_term_definition(context, key, defined)
342342
end
343343
end
@@ -990,7 +990,7 @@ def compact_iri(iri, options = {})
990990
# @raise [RDF::ReaderError] if the iri cannot be expanded
991991
# @see http://json-ld.org/spec/latest/json-ld-api/#value-expansion
992992
def expand_value(property, value, options = {})
993-
options = {useNativeTypes: false}.merge(options)
993+
options = {useNativeTypes: false}.merge!(options)
994994
depth(options) do
995995
debug("expand_value") {"property: #{property.inspect}, value: #{value.inspect}"}
996996

lib/json/ld/expand.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module Expand
1515
# Ensure output objects have keys ordered properly
1616
# @return [Array, Hash]
1717
def expand(input, active_property, context, options = {})
18-
options = {ordered: true}.merge(options)
18+
options = {ordered: true}.merge!(options)
1919
debug("expand") {"input: #{input.inspect}, active_property: #{active_property.inspect}, context: #{context.inspect}"}
2020
result = case input
2121
when Array

lib/json/ld/resource.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def update_obj(obj, reference_map)
174174
stub: true
175175
)
176176
else
177-
obj.keys.each do |k|
177+
obj.each_key do |k|
178178
obj[k] = update_obj(obj[k], reference_map)
179179
end
180180
obj

lib/json/ld/utils.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module Utils
99
# @return [Boolean]
1010
def node?(value)
1111
value.is_a?(Hash) &&
12-
(value.keys & %w(@value @list @set)).empty? &&
12+
!(value.has_key?('@value') || value.has_key?('@list') || value.has_key?('@set')) &&
1313
(value.length > 1 || !value.has_key?('@id'))
1414
end
1515

@@ -118,7 +118,7 @@ def compare_values(v1, v2)
118118
# true to allow duplicates, false not to (uses
119119
# a simple shallow comparison of subject ID or value).
120120
def add_value(subject, property, value, options = {})
121-
options = {property_is_array: false, allow_duplicate: true}.merge(options)
121+
options = {property_is_array: false, allow_duplicate: true}.merge!(options)
122122

123123
if value.is_a?(Array)
124124
subject[property] = [] if value.empty? && options[:property_is_array]
@@ -211,14 +211,13 @@ def merge_compacted_value(hash, key, value)
211211
# Add debug event to debug array, if specified
212212
#
213213
# param [String] message
214-
# yieldreturn [String] appended to message, to allow for lazy-evaulation of message
214+
# yieldreturn [String] appended to message, to allow for lazy-evaluation of message
215215
def debug(*args)
216-
options = args.last.is_a?(Hash) ? args.pop : {}
217216
return unless ::JSON::LD.debug? || @options[:debug]
218-
depth = options[:depth] || @depth || 0
217+
depth = @depth || 0
219218
list = args
220219
list << yield if block_given?
221-
message = " " * depth * 2 + (list.empty? ? "" : list.join(": "))
220+
message = " " * depth * 2 + list.join(": ")
222221
case @options[:debug]
223222
when Array
224223
@options[:debug] << message
@@ -308,4 +307,4 @@ def get_sym(old = "")
308307
end
309308
end
310309
end
311-
end
310+
end

0 commit comments

Comments
 (0)