Nico,
The Smiles pattern matching code uses String.equals(String) to compare
element symbols for equality (or to compare against the "*" wildcard)
The smiles code is being used for pattern matching, so efficiency may be
important.
Java has some special support to speed up string comparisions in cases
like this. The resulting code is smaller, executes faster, and the runtime
memory requirements are smaller.
The Java virtual machine has a special pool of unique 'interned' strings.
They are different from other strings in that all references to 'interned'
strings point to exactly the same object.
Calling
String.intern()
returns a reference to the one, shared 'interned' copy of the string. In
most cases this means that memory gets freed up because references to the
original string get dropped.
Once strings are 'interned' then you can compare them using ==. So this is
an inline comparison of the object pointer values rather than a subroutine
call that compares lengths and then compares character by character.
And, all string constants are guaranteed to be 'interned' ... so they are
exactly the same.
We can apply this to the Smiles code by making the member variable
Smiles.symbol hold the 'interned' value of the string.
this.symbol = symbol.intern();
Then, in SmilesAtom.createMissingHydrogen we can use direct == comparisons
if (symbol == "Br") rather than if (symbol.equals("Br"))
More importantly, in PatternMatcher.searchMatch we can
String patternSymbol = patternAtom.getSymbol()
if (patternSymbol != "*" && patternSymbol != atom.getElementSymbol())
Miguel
-------------------------------------------------------
This SF.net email is sponsored by: 2005 Windows Mobile Application Contest
Submit applications for Windows Mobile(tm)-based Pocket PCs or Smartphones
for the chance to win $25,000 and application distribution. Enter today at
http://ads.osdn.com/?ad_idh82&alloc_id148&op=click
_______________________________________________
Jmol-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jmol-developers