From aa2afb68a78fed7a71a6d574586202a0377eba25 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Thu, 9 Jul 2015 13:51:28 -0700 Subject: yet more cops --- lib/ffi_yajl/benchmark/encode_profile.rb | 24 ++++++++++++------------ lib/ffi_yajl/benchmark/http.rb | 2 +- lib/ffi_yajl/benchmark/parse.rb | 2 +- lib/ffi_yajl/benchmark/parse_json_and_marshal.rb | 2 +- lib/ffi_yajl/benchmark/parse_json_and_yaml.rb | 2 +- lib/ffi_yajl/benchmark/parse_stream.rb | 2 +- lib/ffi_yajl/encoder.rb | 4 ++-- lib/ffi_yajl/ffi/encoder.rb | 4 ++-- 8 files changed, 21 insertions(+), 21 deletions(-) (limited to 'lib') diff --git a/lib/ffi_yajl/benchmark/encode_profile.rb b/lib/ffi_yajl/benchmark/encode_profile.rb index 6158508..2cf19f1 100644 --- a/lib/ffi_yajl/benchmark/encode_profile.rb +++ b/lib/ffi_yajl/benchmark/encode_profile.rb @@ -15,21 +15,21 @@ module FFI_Yajl class Benchmark class EncodeProfile def run - if defined?(PerfTools) - filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "ohai.json")) - hash = File.open(filename, 'rb') { |f| FFI_Yajl::Parser.parse(f.read) } + return unless defined?(PerfTools) - times = 1000 - puts "Starting profiling encoding #{filename} #{times} times\n\n" + filename = File.expand_path(File.join(File.dirname(__FILE__), "subjects", "ohai.json")) + hash = File.open(filename, 'rb') { |f| FFI_Yajl::Parser.parse(f.read) } - ffi_string_encoder = FFI_Yajl::Encoder.new - PerfTools::CpuProfiler.start("/tmp/ffi_yajl_encode_profile.out") do - times.times { - ffi_string_encoder.encode(hash) - } - end - system("pprof.rb --text /tmp/ffi_yajl_encode_profile.out") + times = 1000 + puts "Starting profiling encoding #{filename} #{times} times\n\n" + + ffi_string_encoder = FFI_Yajl::Encoder.new + PerfTools::CpuProfiler.start("/tmp/ffi_yajl_encode_profile.out") do + times.times { + ffi_string_encoder.encode(hash) + } end + system("pprof.rb --text /tmp/ffi_yajl_encode_profile.out") end end end diff --git a/lib/ffi_yajl/benchmark/http.rb b/lib/ffi_yajl/benchmark/http.rb index 4c61df5..771e452 100644 --- a/lib/ffi_yajl/benchmark/http.rb +++ b/lib/ffi_yajl/benchmark/http.rb @@ -26,7 +26,7 @@ Benchmark.bmbm { |x| x.report { puts "JSON.parser" times.times { - JSON.parse(Net::HTTP.get_response(uri).body, :max_nesting => false) + JSON.parse(Net::HTTP.get_response(uri).body, max_nesting: false) } } } diff --git a/lib/ffi_yajl/benchmark/parse.rb b/lib/ffi_yajl/benchmark/parse.rb index 0625e33..7e602fa 100644 --- a/lib/ffi_yajl/benchmark/parse.rb +++ b/lib/ffi_yajl/benchmark/parse.rb @@ -92,7 +92,7 @@ class FFI_Yajl::Benchmark::Parse puts "JSON.parse" times.times { json.rewind - JSON.parse(json.read, :max_nesting => false) + JSON.parse(json.read, max_nesting: false) } } end diff --git a/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb b/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb index 163f559..204ab06 100644 --- a/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb +++ b/lib/ffi_yajl/benchmark/parse_json_and_marshal.rb @@ -34,7 +34,7 @@ Benchmark.bmbm { |x| puts "JSON.parse" times.times { json.rewind - JSON.parse(json.read, :max_nesting => false) + JSON.parse(json.read, max_nesting: false) } } end diff --git a/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb b/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb index 4e96e02..5076f67 100644 --- a/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb +++ b/lib/ffi_yajl/benchmark/parse_json_and_yaml.rb @@ -31,7 +31,7 @@ Benchmark.bmbm { |x| puts "JSON.parse" times.times { json.rewind - JSON.parse(json.read, :max_nesting => false) + JSON.parse(json.read, max_nesting: false) } } end diff --git a/lib/ffi_yajl/benchmark/parse_stream.rb b/lib/ffi_yajl/benchmark/parse_stream.rb index 955f22f..acf776a 100644 --- a/lib/ffi_yajl/benchmark/parse_stream.rb +++ b/lib/ffi_yajl/benchmark/parse_stream.rb @@ -34,7 +34,7 @@ Benchmark.bmbm { |x| times.times { json.rewind while chunk = json.gets - JSON.parse(chunk, :max_nesting => false) + JSON.parse(chunk, max_nesting: false) end } } diff --git a/lib/ffi_yajl/encoder.rb b/lib/ffi_yajl/encoder.rb index 9f2e564..f4dd8c8 100644 --- a/lib/ffi_yajl/encoder.rb +++ b/lib/ffi_yajl/encoder.rb @@ -41,7 +41,7 @@ module FFI_Yajl # call either the ext or ffi hook str = do_yajl_encode(obj, yajl_gen_opts, opts) # we can skip cleaning the whole string for utf-8 issues if we have yajl validate as we go - str.encode!("utf-8", "binary", :undef => :replace) unless yajl_gen_opts[:yajl_gen_validate_utf8] + str.encode!("utf-8", "binary", undef: :replace) unless yajl_gen_opts[:yajl_gen_validate_utf8] str end @@ -56,7 +56,7 @@ module FFI_Yajl def self.raise_error_for_status(status, token = nil) # scrub token to valid utf-8 since we may be issuing an exception on an invalid utf-8 token - token = token.to_s.encode("utf-8", "binary", :undef => :replace) + token = token.to_s.encode("utf-8", "binary", undef: :replace) case status when 1 # yajl_gen_keys_must_be_strings raise FFI_Yajl::EncodeError, "YAJL internal error: attempted use of non-string object as key" diff --git a/lib/ffi_yajl/ffi/encoder.rb b/lib/ffi_yajl/ffi/encoder.rb index 250ed68..51a3c7a 100644 --- a/lib/ffi_yajl/ffi/encoder.rb +++ b/lib/ffi_yajl/ffi/encoder.rb @@ -41,8 +41,8 @@ module FFI_Yajl # setup our own state state = { - :json_opts => opts, - :processing_key => false, + json_opts: opts, + processing_key: false, } # do the encoding -- cgit v1.2.1