From 9e0d471466997fce4b59ac88d6bd8ad0108b8974 Mon Sep 17 00:00:00 2001 From: Luboš Luňák Date: Sat, 27 Nov 2021 23:55:41 +0100 Subject: move entire ScTable::ValidQuery() into (Sc)QueryEvaluator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reduces the number of arguments passed around, removed the need for ValidQueryCache (as the data can be now cached in the class itself), it'll allow even more optimizations, and it also makes the by now rather large (almost 1000 lines) helper class a proper class instead of tons of inline code. Change-Id: I585cf580b3e7b2d4512aa535176e97c0abfd547a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126367 Tested-by: Jenkins Reviewed-by: Luboš Luňák --- sc/inc/queryevaluator.hxx | 123 ++++++++++++++++++++++++++++++++++++++++++++++ sc/inc/table.hxx | 17 +------ 2 files changed, 125 insertions(+), 15 deletions(-) create mode 100644 sc/inc/queryevaluator.hxx (limited to 'sc/inc') diff --git a/sc/inc/queryevaluator.hxx b/sc/inc/queryevaluator.hxx new file mode 100644 index 000000000000..3caa1c57dfcf --- /dev/null +++ b/sc/inc/queryevaluator.hxx @@ -0,0 +1,123 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include +#include +#include + +#include "queryentry.hxx" + +class ScDocument; +class ScTable; +struct ScQueryParam; +class CollatorWrapper; +struct ScRefCellValue; +struct ScInterpreterContext; + +namespace sc +{ +class TableColumnBlockPositionSet; +} +namespace svl +{ +class SharedStringPool; +} +namespace utl +{ +class TransliterationWrapper; +} + +class ScQueryEvaluator +{ + ScDocument& mrDoc; + svl::SharedStringPool& mrStrPool; + const ScTable& mrTab; + const ScQueryParam& mrParam; + bool* mpTestEqualCondition; + utl::TransliterationWrapper* mpTransliteration; + CollatorWrapper* mpCollator; + const bool mbMatchWholeCell; + const bool mbCaseSensitive; + const ScInterpreterContext* mpContext; + + const SCSIZE mnEntryCount; + bool* mpPasst; + bool* mpTest; + static constexpr SCSIZE nFixedBools = 32; + bool maBool[nFixedBools]; + bool maTest[nFixedBools]; + std::unique_ptr mpBoolDynamic; + std::unique_ptr mpTestDynamic; + + std::unordered_map mCachedSharedErrorStrings; + std::vector mCachedSortedItemValues; + std::vector mCachedSortedItemStrings; + bool mCachedSortedItemValuesReady = false; + bool mCachedSortedItemStringsReady = false; + + static bool isPartialTextMatchOp(const ScQueryEntry& rEntry); + static bool isTextMatchOp(const ScQueryEntry& rEntry); + void setupTransliteratorIfNeeded(); + void setupCollatorIfNeeded(); + + bool isRealWildOrRegExp(const ScQueryEntry& rEntry) const; + bool isTestWildOrRegExp(const ScQueryEntry& rEntry) const; + static bool isQueryByValue(const ScQueryEntry::Item& rItem, const ScRefCellValue& rCell); + static bool isQueryByValueForCell(const ScRefCellValue& rCell); + static bool isQueryByString(const ScQueryEntry& rEntry, const ScQueryEntry::Item& rItem, + const ScRefCellValue& rCell); + + sal_uInt32 getNumFmt(SCCOL nCol, SCROW nRow); + + std::pair compareByValue(const ScRefCellValue& rCell, SCCOL nCol, SCROW nRow, + const ScQueryEntry& rEntry, + const ScQueryEntry::Item& rItem); + + OUString getCellString(const ScRefCellValue& rCell, SCROW nRow, const ScQueryEntry& rEntry, + const svl::SharedString** sharedString); + + bool isFastCompareByString(const ScQueryEntry& rEntry) const; + template + std::pair + compareByString(const ScQueryEntry& rEntry, const ScQueryEntry::Item& rItem, + const svl::SharedString* pValueSource1, const OUString* pValueSource2); + std::pair compareByTextColor(SCCOL nCol, SCROW nRow, + const ScQueryEntry::Item& rItem); + std::pair compareByBackgroundColor(SCCOL nCol, SCROW nRow, + const ScQueryEntry::Item& rItem); + + static std::pair compareByRangeLookup(const ScRefCellValue& rCell, + const ScQueryEntry& rEntry, + const ScQueryEntry::Item& rItem); + + std::pair processEntry(SCROW nRow, SCCOL nCol, ScRefCellValue& aCell, + const ScQueryEntry& rEntry); + +public: + ScQueryEvaluator(ScDocument& rDoc, const ScTable& rTab, const ScQueryParam& rParam, + const ScInterpreterContext* pContext = nullptr, + bool* pTestEqualCondition = nullptr); + + bool ValidQuery(SCROW nRow, const ScRefCellValue* pCell = nullptr, + sc::TableColumnBlockPositionSet* pBlockPos = nullptr); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 0bb6548d5dd9..672d8431dfe4 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -466,6 +466,7 @@ public: return aCol[rPos.Col()].GetCellType( rPos.Row() ); } CellType GetCellType( SCCOL nCol, SCROW nRow ) const; + ScRefCellValue GetCellValue( SCCOL nCol, sc::ColumnBlockPosition& rBlockPos, SCROW nRow ); ScRefCellValue GetCellValue( SCCOL nCol, SCROW nRow ) const; void GetFirstDataPos(SCCOL& rCol, SCROW& rRow) const; @@ -954,21 +955,7 @@ public: void Reorder( const sc::ReorderParam& rParam ); - // Internal cache that can be repeatedly used for a sequence of related ValidQuery() - // calls (related meaning done in a loop for the same document and query data). - struct ValidQueryCache - { - std::unordered_map mCachedSharedErrorStrings; - std::vector mCachedSortedItemValues; - std::vector mCachedSortedItemStrings; - bool mCachedSortedItemValuesReady = false; - bool mCachedSortedItemStringsReady = false; - }; - bool ValidQuery( - SCROW nRow, const ScQueryParam& rQueryParam, const ScRefCellValue* pCell = nullptr, - bool* pbTestEqualCondition = nullptr, const ScInterpreterContext* pContext = nullptr, - sc::TableColumnBlockPositionSet* pBlockPos = nullptr, - ValidQueryCache* pQueryCache = nullptr ); + // For ValidQuery() see ScQueryEvalutor class. void TopTenQuery( ScQueryParam& ); void PrepareQuery( ScQueryParam& rQueryParam ); SCSIZE Query(const ScQueryParam& rQueryParam, bool bKeepSub); -- cgit