Can any compilers recognize the optimization for this scenario? -
suppose have method (java chosen arbitrarily, similar language):
public set<string> createset() {...} this method creates set adding strings it, 1 @ time.
then suppose call here in loop many times:
boolean contained = createset().contains(somestring); in ideal world, compiler recognize code improved creating separate method, increatedset(string), run createset(), except instead of putting strings set, compare them against somestring directly, eliminate set creation , end method somestring found, no need continue (assuming no side effects).
i know java compilers don't optimization @ compile time , wouldn't recognize in jit either, there optimizers out there able sort of advanced analysis of code?
Comments
Post a Comment