1 | /* $Id: strcache-stubs-generic.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - String Cache, stub implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * The contents of this file may alternatively be used under the terms
|
---|
26 | * of the Common Development and Distribution License Version 1.0
|
---|
27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | * CDDL are applicable instead of those of the GPL.
|
---|
30 | *
|
---|
31 | * You may elect to license modified versions of this file under the
|
---|
32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | *
|
---|
34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | */
|
---|
36 |
|
---|
37 |
|
---|
38 | /*********************************************************************************************************************************
|
---|
39 | * Header Files *
|
---|
40 | *********************************************************************************************************************************/
|
---|
41 | #include <iprt/strcache.h>
|
---|
42 | #include "internal/iprt.h"
|
---|
43 |
|
---|
44 | #include <iprt/asm.h>
|
---|
45 | #include <iprt/assert.h>
|
---|
46 | #include <iprt/errcore.h>
|
---|
47 | #include <iprt/mempool.h>
|
---|
48 | #include <iprt/string.h>
|
---|
49 |
|
---|
50 |
|
---|
51 |
|
---|
52 | RTDECL(int) RTStrCacheCreate(PRTSTRCACHE phStrCache, const char *pszName)
|
---|
53 | {
|
---|
54 | AssertCompile(sizeof(RTSTRCACHE) == sizeof(RTMEMPOOL));
|
---|
55 | AssertCompileNS(NIL_RTSTRCACHE == (RTSTRCACHE)NIL_RTMEMPOOL);
|
---|
56 | AssertCompileNS(RTSTRCACHE_DEFAULT == (RTSTRCACHE)RTMEMPOOL_DEFAULT);
|
---|
57 | return RTMemPoolCreate((PRTMEMPOOL)phStrCache, pszName);
|
---|
58 | }
|
---|
59 | RT_EXPORT_SYMBOL(RTStrCacheCreate);
|
---|
60 |
|
---|
61 |
|
---|
62 | RTDECL(int) RTStrCacheDestroy(RTSTRCACHE hStrCache)
|
---|
63 | {
|
---|
64 | if ( hStrCache == NIL_RTSTRCACHE
|
---|
65 | || hStrCache == RTSTRCACHE_DEFAULT)
|
---|
66 | return VINF_SUCCESS;
|
---|
67 | return RTMemPoolDestroy((RTMEMPOOL)hStrCache);
|
---|
68 | }
|
---|
69 | RT_EXPORT_SYMBOL(RTStrCacheDestroy);
|
---|
70 |
|
---|
71 |
|
---|
72 | RTDECL(const char *) RTStrCacheEnterN(RTSTRCACHE hStrCache, const char *pchString, size_t cchString)
|
---|
73 | {
|
---|
74 | AssertPtr(pchString);
|
---|
75 | AssertReturn(cchString < _1G, NULL);
|
---|
76 | Assert(!RTStrEnd(pchString, cchString));
|
---|
77 |
|
---|
78 | return (const char *)RTMemPoolDupEx((RTMEMPOOL)hStrCache, pchString, cchString, 1);
|
---|
79 | }
|
---|
80 | RT_EXPORT_SYMBOL(RTStrCacheEnterN);
|
---|
81 |
|
---|
82 |
|
---|
83 | RTDECL(const char *) RTStrCacheEnter(RTSTRCACHE hStrCache, const char *psz)
|
---|
84 | {
|
---|
85 | return RTStrCacheEnterN(hStrCache, psz, strlen(psz));
|
---|
86 | }
|
---|
87 | RT_EXPORT_SYMBOL(RTStrCacheEnter);
|
---|
88 |
|
---|
89 |
|
---|
90 | RTDECL(const char *) RTStrCacheEnterLowerN(RTSTRCACHE hStrCache, const char *pchString, size_t cchString)
|
---|
91 | {
|
---|
92 | AssertPtr(pchString);
|
---|
93 | AssertReturn(cchString < _1G, NULL);
|
---|
94 | Assert(!RTStrEnd(pchString, cchString));
|
---|
95 |
|
---|
96 | char *pszRet = (char *)RTMemPoolDupEx((RTMEMPOOL)hStrCache, pchString, cchString, 1);
|
---|
97 | if (pszRet)
|
---|
98 | RTStrToLower(pszRet);
|
---|
99 | return pszRet;
|
---|
100 | }
|
---|
101 | RT_EXPORT_SYMBOL(RTStrCacheEnterLowerN);
|
---|
102 |
|
---|
103 |
|
---|
104 | RTDECL(const char *) RTStrCacheEnterLower(RTSTRCACHE hStrCache, const char *psz)
|
---|
105 | {
|
---|
106 | return RTStrCacheEnterLowerN(hStrCache, psz, strlen(psz));
|
---|
107 | }
|
---|
108 | RT_EXPORT_SYMBOL(RTStrCacheEnterLower);
|
---|
109 |
|
---|
110 |
|
---|
111 | RTDECL(uint32_t) RTStrCacheRetain(const char *psz)
|
---|
112 | {
|
---|
113 | AssertPtr(psz);
|
---|
114 | return RTMemPoolRetain((void *)psz);
|
---|
115 | }
|
---|
116 | RT_EXPORT_SYMBOL(RTStrCacheRetain);
|
---|
117 |
|
---|
118 |
|
---|
119 | RTDECL(uint32_t) RTStrCacheRelease(RTSTRCACHE hStrCache, const char *psz)
|
---|
120 | {
|
---|
121 | if (!psz)
|
---|
122 | return 0;
|
---|
123 | return RTMemPoolRelease((RTMEMPOOL)hStrCache, (void *)psz);
|
---|
124 | }
|
---|
125 | RT_EXPORT_SYMBOL(RTStrCacheRelease);
|
---|
126 |
|
---|
127 |
|
---|
128 | RTDECL(size_t) RTStrCacheLength(const char *psz)
|
---|
129 | {
|
---|
130 | if (!psz)
|
---|
131 | return 0;
|
---|
132 | return strlen(psz);
|
---|
133 | }
|
---|
134 | RT_EXPORT_SYMBOL(RTStrCacheLength);
|
---|
135 |
|
---|
136 |
|
---|
137 | RTDECL(bool) RTStrCacheIsRealImpl(void)
|
---|
138 | {
|
---|
139 | return false;
|
---|
140 | }
|
---|
141 | RT_EXPORT_SYMBOL(RTStrCacheIsRealImpl);
|
---|
142 |
|
---|
143 |
|
---|
144 | RTDECL(uint32_t) RTStrCacheGetStats(RTSTRCACHE hStrCache, size_t *pcbStrings, size_t *pcbChunks, size_t *pcbBigEntries,
|
---|
145 | uint32_t *pcHashCollisions, uint32_t *pcHashCollisions2, uint32_t *pcHashInserts,
|
---|
146 | uint32_t *pcRehashes)
|
---|
147 | {
|
---|
148 | return UINT32_MAX;
|
---|
149 | }
|
---|
150 | RT_EXPORT_SYMBOL(RTStrCacheGetStats);
|
---|
151 |
|
---|