diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-09-10 17:08:15 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-09-11 13:09:26 +0200 |
commit | 3b918495513d8e43063a45ac500962703e08f94e (patch) | |
tree | 768254cdd00ef744ae7421d678d7efde28e7b408 /comphelper/source | |
parent | 1c271e9fdcea1832378995c9c43619290060f378 (diff) |
small optimisation
avoid allocating predicate on heap, which is expensive when walking over
large numbers of styles nodes
Change-Id: Ida4369b77fb74f3af1258a97b0b99e3a78413833
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102437
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'comphelper/source')
-rw-r--r-- | comphelper/source/misc/anycompare.cxx | 64 |
1 files changed, 60 insertions, 4 deletions
diff --git a/comphelper/source/misc/anycompare.cxx b/comphelper/source/misc/anycompare.cxx index bb77544c957e..72156024ccd0 100644 --- a/comphelper/source/misc/anycompare.cxx +++ b/comphelper/source/misc/anycompare.cxx @@ -235,10 +235,66 @@ namespace comphelper auto rhsTypeClass = rhs.getValueType().getTypeClass(); if (lhsTypeClass != rhsTypeClass) return lhsTypeClass < rhsTypeClass; - std::unique_ptr< IKeyPredicateLess > pred = getStandardLessPredicate( lhs.getValueType(), Reference< XCollator >() ); - if (!pred) // type==VOID - return false; - return pred->isLess(lhs, rhs); + + switch ( lhsTypeClass ) + { + case TypeClass_CHAR: + return ScalarPredicateLess< sal_Unicode >().isLess(lhs, rhs); + case TypeClass_BOOLEAN: + return ScalarPredicateLess< bool >().isLess(lhs, rhs); + break; + case TypeClass_BYTE: + return ScalarPredicateLess< sal_Int8 >().isLess(lhs, rhs); + break; + case TypeClass_SHORT: + return ScalarPredicateLess< sal_Int16 >().isLess(lhs, rhs); + break; + case TypeClass_UNSIGNED_SHORT: + return ScalarPredicateLess< sal_uInt16 >().isLess(lhs, rhs); + break; + case TypeClass_LONG: + return ScalarPredicateLess< sal_Int32 >().isLess(lhs, rhs); + break; + case TypeClass_UNSIGNED_LONG: + return ScalarPredicateLess< sal_uInt32 >().isLess(lhs, rhs); + break; + case TypeClass_HYPER: + return ScalarPredicateLess< sal_Int64 >().isLess(lhs, rhs); + break; + case TypeClass_UNSIGNED_HYPER: + return ScalarPredicateLess< sal_uInt64 >().isLess(lhs, rhs); + break; + case TypeClass_FLOAT: + return ScalarPredicateLess< float >().isLess(lhs, rhs); + break; + case TypeClass_DOUBLE: + return ScalarPredicateLess< double >().isLess(lhs, rhs); + break; + case TypeClass_STRING: + return StringPredicateLess().isLess(lhs, rhs); + break; + case TypeClass_TYPE: + return TypePredicateLess().isLess(lhs, rhs); + break; + case TypeClass_ENUM: + return EnumPredicateLess( lhs.getValueType() ).isLess(lhs, rhs); + break; + case TypeClass_INTERFACE: + return InterfacePredicateLess().isLess(lhs, rhs); + break; + case TypeClass_STRUCT: + if ( lhs.getValueType().equals( ::cppu::UnoType< Date >::get() ) ) + return DatePredicateLess().isLess(lhs, rhs); + else if ( lhs.getValueType().equals( ::cppu::UnoType< Time >::get() ) ) + return TimePredicateLess().isLess(lhs, rhs); + else if ( lhs.getValueType().equals( ::cppu::UnoType< DateTime >::get() ) ) + return DateTimePredicateLess().isLess(lhs, rhs); + break; + default: ; + } + + // type==VOID + return false; } } // namespace comphelper |