DO NOT REPLY [Bug 35037] - [PATCH] Some Field methods use Classcast check instead of instanceof which is slow

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

DO NOT REPLY [Bug 35037] - [PATCH] Some Field methods use Classcast check instead of instanceof which is slow

Bugzilla from bugzilla@apache.org
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG?
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=35037>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND?
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=35037





------- Additional Comments From [hidden email]  2005-05-25 01:08 -------
The area of code that is affected by this is in
DocumentWriter.invertDocument(Document):

...
          Reader reader;  // find or make Reader
          if (field.readerValue() != null)
            reader = field.readerValue();
          else if (field.stringValue() != null)
            reader = new StringReader(field.stringValue());
          else
            throw new IllegalArgumentException
                    ("field must have either String or Reader value");


In my test scenario I do not use a reader, all my Fields are created as normal
String values, so the first if() to determine if the reader comes back null will
always result in an ClassCastException.  

That's 1 ClassCastException for each Indexed & Tokenized field _per_ Document.

I'm not sure of whether String/Reader is more prevelant out there in the wild,
but I would have thought String would have been common.  Sure for large
documents like PDF's etc it's more likely a Reader will be used.

Anyway, for the try/catch block, the JVM performs an implicit ClassCast check
anyway, that's how it determines whether it should throw an exception or not, so
there is no way to avoid some form of an instanceof.

Modern JVM's are quicker with instanceof.  However this may not (probably not)
true for older (1.2 or earlier?) VM's, although I don't have access to that
anymore test that theory.

--
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]