From 9a25d2d5e81a45a639c75bed37a27ebe643127d7 Mon Sep 17 00:00:00 2001 From: deadprogrammer Date: Tue, 5 Apr 2011 21:43:37 -0700 Subject: [PATCH] JSON why do you kill my performance? Oh yeah... --- Gemfile | 5 +++-- Gemfile.lock | 2 -- app/widgets/server.rb | 4 +--- lib/kidsruby/interface.rb | 3 +-- lib/kidsruby/stdio.rb | 4 +--- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/Gemfile b/Gemfile index 10230da..14836c8 100644 --- a/Gemfile +++ b/Gemfile @@ -3,6 +3,7 @@ source "http://rubygems.org" gem "qtbindings" gem 'htmlentities' +gem 'rest-client' + +# only needed for testing gem 'mocha' -gem 'json_pure' -gem 'rest-client' \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 5abdbe2..0cff62d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,7 +2,6 @@ GEM remote: http://rubygems.org/ specs: htmlentities (4.2.3) - json_pure (1.5.1) mime-types (1.16) mocha (0.9.10) rake @@ -16,7 +15,6 @@ PLATFORMS DEPENDENCIES htmlentities - json_pure mocha qtbindings rest-client diff --git a/app/widgets/server.rb b/app/widgets/server.rb index 2a94efc..e167cd8 100644 --- a/app/widgets/server.rb +++ b/app/widgets/server.rb @@ -1,5 +1,4 @@ require 'uri' -require 'json/pure' # http server listening on port 8080 to do the inter-process communication class KidsRubyServer < Qt::TcpServer @@ -86,8 +85,7 @@ def connection @parent.append(param) connection.write validResponse("OK") elsif command == "appendError" - body.each_line {|l| @parent.appendError( JSON.parse(l)['error'] )} - #@parent.appendError(body) + @parent.appendError(body) connection.write validResponse("OK") elsif command == "gets" connection.write validResponse(@parent.gets) diff --git a/lib/kidsruby/interface.rb b/lib/kidsruby/interface.rb index 58c8643..19f94f9 100644 --- a/lib/kidsruby/interface.rb +++ b/lib/kidsruby/interface.rb @@ -1,6 +1,5 @@ require "uri" require "rest_client" -require 'json/pure' class InterfaceHelper def connect! @@ -34,7 +33,7 @@ def call(method, param = nil) loc = loc + "?#{URI.escape(param)}" return Reply.new(RestClient.get(loc)) elsif param && param.is_a?(Hash) - return Reply.new(RestClient.post(loc, JSON.generate(param), :content_type => :json, :accept => :json)) + return Reply.new(RestClient.post(loc, param['data'], :content_type => 'text/plain')) else return Reply.new(RestClient.get(loc)) end diff --git a/lib/kidsruby/stdio.rb b/lib/kidsruby/stdio.rb index d21349e..fbc8b4b 100644 --- a/lib/kidsruby/stdio.rb +++ b/lib/kidsruby/stdio.rb @@ -14,9 +14,7 @@ def write(data) class StdErr < KidsRubyStdIo def write(data) - #t = data.gsub(/\n/,"
") - @payload = {'error' => data} - @iface.call("appendError", @payload) + @iface.call("appendError", {'data' => data}) end alias_method :puts, :write end