[Nitro] Concerns over Og mandating the form of initialize

James Britt james_b at neurogami.com
Tue Apr 12 12:29:06 EDT 2005

Anastasios Koutoumanos wrote:
> James Britt wrote:

>> Perhaps this could be replaced with something that first tries to 
>> populate the object by passing a block to klass.new.
> Now, that's a great idea, I think it's straight-forward to implement. 
> The only issue that may arise is a performance penalty for  first trying 
> to pass the block and then fall back to the original techique. Since 
> nitro is for speed (among other things), we should "join forces" for 
> using the right way of implementing your idea, minimizing this 
> performance penalty.

In the example code (object_init) , the first part assumes the method 
takes a block. If that is not true, the block is never called, though 
the object is created (which has to happen either way).

If the block *is* called, the method exits before trying the non-block 
version. Otherwise, the accessors are invoked on the object.

I don't think this is an expensive test; actually, I don't see any extra 
overhead at all, other than using hash.shift (which may be marginally 
more expensive than a non-destructive iteration over the hash).

It's not as though the block is executed on every call  If 'initialize' 
never calls yield, the block is never executed.

So, read_all, in each adapter, might have:

res.each do |row|
   obj = object_init( klass, row )

Each adapter may have to implement object_init, because each database 
has a different way of defining a 'row'.


More information about the Nitro-general mailing list