LibreOffice Module vcl (master) 1
TextLayoutCache.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#pragma once
21
22#include <sal/types.h>
23#include <rtl/ustring.hxx>
24#include <o3tl/hash_combine.hxx>
25
26#include <vcl/dllapi.h>
27
28#include <unicode/uscript.h>
29
30#include <vector>
31
32namespace vcl::text
33{
34struct Run
35{
36 int32_t nStart;
37 int32_t nEnd;
38 UScriptCode nCode;
39 Run(int32_t nStart_, int32_t nEnd_, UScriptCode nCode_)
40 : nStart(nStart_)
41 , nEnd(nEnd_)
42 , nCode(nCode_)
43 {
44 }
45};
46
48{
49public:
50 std::vector<vcl::text::Run> runs;
51 TextLayoutCache(sal_Unicode const* pStr, sal_Int32 const nEnd);
52 // Creates a cached instance.
53 static std::shared_ptr<const vcl::text::TextLayoutCache> Create(OUString const&);
54};
55
57{
58 size_t operator()(const OUString& str) const
59 {
60 // Strings passed to GenericSalLayout::CreateTextLayoutCache() may be very long,
61 // and computing an entire hash could almost negate the gain of hashing. Hash just first
62 // characters, that should be good enough.
63 size_t hash
64 = rtl_ustr_hashCode_WithLength(str.getStr(), std::min<size_t>(100, str.getLength()));
65 o3tl::hash_combine(hash, str.getLength());
66 return hash;
67 }
68};
69
71{
72 bool operator()(const OUString& str1, const OUString& str2) const
73 {
74 // Strings passed to GenericSalLayout::CreateTextLayoutCache() may be very long,
75 // and OUString operator == compares backwards and using hard-written code, while
76 // memcmp() compares much faster.
77 if (str1.getLength() != str2.getLength())
78 return false;
79 if (str1.getStr() == str2.getStr())
80 return true;
81 return memcmp(str1.getStr(), str2.getStr(), str1.getLength() * sizeof(str1.getStr()[0]))
82 == 0;
83 }
84};
85}
86
87/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
std::vector< vcl::text::Run > runs
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
std::enable_if_t<(sizeof(N)==4)> hash_combine(N &nSeed, T const *pValue, size_t nCount)
bool operator()(const OUString &str1, const OUString &str2) const
size_t operator()(const OUString &str) const
Run(int32_t nStart_, int32_t nEnd_, UScriptCode nCode_)
UScriptCode nCode
sal_uInt16 sal_Unicode