Academically curious. Can the JIT take code like this, recognize that the format string is static final and thus precompute the sliced format string, thus optimizing this down to only StringBuilder with minimal appends?
public static String buildDeleteSql(BaseObject object)
{
String table;
String schema;
String deleteSql = String.format(
"DELETE FROM %s.%s WHERE %s = '%s' AND %s = '%s'",
schema,
table,
BaseObject.ATTR_ID,
StringUtils.escapeForSQLString(object.getId()),
BaseObject.ATTR_REVISION,
StringUtils.escapeForSQLString(object.getRevision())
);
return deleteSql;
}
Theoretically, a JVM could probably grok your example. Meantime, in reality, existing JVMs won't; it's probably not a very lucrative place to spend the budget for optimizations. Especially since string formatting is usually done to serialize data, in which case you'll probably end up spending most of the time waiting for I/O to complete.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With