/src/libreoffice/svl/source/misc/sharedstring.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
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 | | |
10 | | #include <svl/sharedstring.hxx> |
11 | | |
12 | | namespace svl { |
13 | | |
14 | | const OUString SharedString::EMPTY_STRING; |
15 | | |
16 | | const SharedString & SharedString::getEmptyString() |
17 | 54.3k | { |
18 | | // ref-counting traffic associated with SharedString temporaries can be significant, |
19 | | // so use a singleton here, so we can return a const& from getEmptyString. |
20 | | // unicode string array for empty string is globally shared in OUString. |
21 | | // Let's take advantage of that. |
22 | 54.3k | static const SharedString EMPTY_SHARED_STRING(EMPTY_STRING.pData, EMPTY_STRING.pData); |
23 | 54.3k | return EMPTY_SHARED_STRING; |
24 | 54.3k | } |
25 | | |
26 | | SharedString& SharedString::operator= ( const SharedString& r ) |
27 | 473k | { |
28 | 473k | if(this == &r) |
29 | 294 | return *this; |
30 | | |
31 | 472k | if (mpData) |
32 | 302k | rtl_uString_release(mpData); |
33 | 472k | if (mpDataIgnoreCase) |
34 | 302k | rtl_uString_release(mpDataIgnoreCase); |
35 | | |
36 | 472k | mpData = r.mpData; |
37 | 472k | mpDataIgnoreCase = r.mpDataIgnoreCase; |
38 | | |
39 | 472k | if (mpData) |
40 | 457k | rtl_uString_acquire(mpData); |
41 | 472k | if (mpDataIgnoreCase) |
42 | 457k | rtl_uString_acquire(mpDataIgnoreCase); |
43 | | |
44 | 472k | return *this; |
45 | 473k | } |
46 | | |
47 | | bool SharedString::operator== ( const SharedString& r ) const |
48 | 2.63M | { |
49 | | // Compare only the original (not case-folded) string. |
50 | | |
51 | 2.63M | if (mpData == r.mpData) |
52 | 2.54M | return true; |
53 | | |
54 | 83.6k | if (!mpData || !r.mpData) |
55 | 0 | return false; |
56 | | |
57 | 83.6k | if (mpData->length != r.mpData->length) |
58 | 40.1k | return false; |
59 | | |
60 | 43.5k | return rtl_ustr_reverseCompare_WithLength(mpData->buffer, mpData->length, r.mpData->buffer, r.mpData->length) == 0; |
61 | 83.6k | } |
62 | | |
63 | | } |
64 | | |
65 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |