mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 13:10:44 +00:00
Bypass calling String.formatted for most common case: "%s" (seen to be a hotspot in huge exports)
This commit is contained in:
@ -119,6 +119,15 @@ public class QValueFormatter
|
||||
////////////////////////////////////////////////////////
|
||||
if(StringUtils.hasContent(displayFormat))
|
||||
{
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// if the format is %s (the default), just return value a string //
|
||||
// this saves some overhead incurred by String.formatted when called millions of times. //
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
if(displayFormat.equals("%s"))
|
||||
{
|
||||
return (ValueUtils.getValueAsString(value));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return (displayFormat.formatted(value));
|
||||
|
@ -57,6 +57,10 @@ class QValueFormatterTest extends BaseTest
|
||||
{
|
||||
assertNull(QValueFormatter.formatValue(new QFieldMetaData().withDisplayFormat(DisplayFormat.COMMAS), null));
|
||||
|
||||
assertEquals("1", QValueFormatter.formatValue(new QFieldMetaData(), 1));
|
||||
assertEquals("1", QValueFormatter.formatValue(new QFieldMetaData().withDisplayFormat("%s"), 1));
|
||||
assertEquals("Hello", QValueFormatter.formatValue(new QFieldMetaData().withDisplayFormat("%s"), "Hello"));
|
||||
|
||||
assertEquals("1", QValueFormatter.formatValue(new QFieldMetaData().withDisplayFormat(DisplayFormat.COMMAS), 1));
|
||||
assertEquals("1,000", QValueFormatter.formatValue(new QFieldMetaData().withDisplayFormat(DisplayFormat.COMMAS), 1000));
|
||||
assertEquals("1000", QValueFormatter.formatValue(new QFieldMetaData().withDisplayFormat(null), 1000));
|
||||
|
Reference in New Issue
Block a user