rb: Check Thrift.type_checking earlier for a performance boost [THRIFT-55]
authorKevin Clark <kclark@apache.org>
Tue, 8 Jul 2008 23:30:13 +0000 (23:30 +0000)
committerKevin Clark <kclark@apache.org>
Tue, 8 Jul 2008 23:30:13 +0000 (23:30 +0000)
Author: Kevin Ballard <kevin@rapleaf.com>

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@675053 13f79535-47bb-0310-9956-ffa450edef68

lib/rb/lib/thrift/struct.rb
lib/rb/lib/thrift/types.rb
lib/rb/spec/types_spec.rb

index 0535948..d8e8f65 100644 (file)
@@ -6,7 +6,7 @@ module Thrift
     def initialize(d={})
       each_field do |fid, type, name, default|
         value = d.delete(name.to_s) { d.delete(name.to_sym) { default.dup rescue default } }
-        Thrift.check_type(value, type)
+        Thrift.check_type(value, type) if Thrift.type_checking
         instance_variable_set("@#{name}", value)
       end
       raise Exception, "Unknown keys given to #{self.class}.new: #{d.keys.join(", ")}" unless d.empty?
@@ -72,7 +72,7 @@ module Thrift
       fields.each do |field|
         klass.send :attr_reader, field
         klass.send :define_method, "#{field}=" do |value|
-          Thrift.check_type(value, klass::FIELDS.values.find { |f| f[:name].to_s == field.to_s }[:type] )
+          Thrift.check_type(value, klass::FIELDS.values.find { |f| f[:name].to_s == field.to_s }[:type] ) if Thrift.type_checking
           instance_variable_set("@#{field}", value)
         end
       end
index d7d4cec..6666a48 100644 (file)
@@ -26,7 +26,7 @@ module Thrift
   end
 
   def self.check_type(value, type)
-    return unless Thrift.type_checking and not value.nil?
+    return if value.nil?
     klasses = case type
               when Types::VOID
                 NilClass
index 4c2b4ea..564d9a6 100644 (file)
@@ -47,6 +47,7 @@ class ThriftTypesSpec < Spec::ExampleGroup
     end
 
     it "should be disabled when Thrift.type_checking = false" do
+      pending "disabled, parents should check Thrift.type_checking"
       Thrift.type_checking = false
       lambda { Thrift.check_type(3, Types::STRING) }.should_not raise_error(TypeError)
     end