[JAVA-165] Unnecessary calls to containsKey Created: 14/Sep/10  Updated: 29/Oct/10  Resolved: 28/Oct/10

Status: Closed
Project: Java Driver
Component/s: Performance
Affects Version/s: 2.1
Fix Version/s: 2.3

Type: Improvement Priority: Minor - P4
Reporter: Hans Meiser Assignee: Eliot Horowitz (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

If there is an array of objects method objectStart() in DBCallback resets _lastArray
so that objectDone() of the array calls containsKey() unnecessarily.
Replace _lastArray with instanceOf List ?



 Comments   
Comment by auto [ 28/Oct/10 ]

Author:

{'login': 'erh', 'name': 'Eliot Horowitz', 'email': 'eliot@10gen.com'}

Message: fix stack handling in DBCallback JAVA-165
http://github.com/mongodb/mongo-java-driver/commit/c45fc7ec209478e72517d8b29324b44c8e25343c

Comment by Hans Meiser [ 25/Oct/10 ]

If we have

a:[

{x:1}

,

{x:2}

]

objectStart(true,'a') --> _lastArray==true
objectStart(false,'x') --> _lastArray==false
objectDone()
objectStart(false,'x') --> _lastArray==false
objectDone()

In the method objectDone there is a check for _lastArray==false but _lastArray is false for all documents within an array.
The method does unnecessary checks for $ref and $id

public Object objectDone(){
BSONObject o = (BSONObject)super.objectDone();
if ( ! _lastArray &&
o.containsKey( "$ref" ) &&
o.containsKey( "$id" ) )

{ return cur().put( _lastName , new DBRef( _db, o ) ); }

return o;
}

would become

if(o instanceOf List) {
if(o.containsKey( "$ref" ) && o.containsKey( "$id" ) )
return cur().put( _lastName , new DBRef( _db, o ) );
}

Comment by Eliot Horowitz (Inactive) [ 25/Oct/10 ]

Can you explain a bit more.
Not seing what you are.

Generated at Thu Feb 08 08:51:38 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.