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开发者_Go百科'",
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.
精彩评论