…lines 1–6 unchanged (6 lines)
7 * must stay backwards-compatible!
8 */
9
10#include "postgres.h"
11#include "ltree.h"
12
13#include "crc32.h"
14#include "utils/pg_crc.h"
15#ifdef LOWER_NODE
16#include "utils/pg_locale.h"
17#endif
18
19#ifdef LOWER_NODE
20
21unsigned int
22ltree_crc32_sz(const char *buf, int size)
23{
24 pg_crc32 crc;
25 const char *p = buf;
26 static pg_locale_t locale = NULL;
27
28 if (!locale)
29 locale = pg_database_locale();
30
31 INIT_TRADITIONAL_CRC32(crc);
32 while (size > 0)
33 {
34 char foldstr[UNICODE_CASEMAP_BUFSZ];
35 int srclen = pg_mblen(p);
36 size_t foldlen;
37
38 /* fold one codepoint at a time */
39 foldlen = pg_strfold(foldstr, UNICODE_CASEMAP_BUFSZ, p, srclen,
40 locale);
41
42 COMP_TRADITIONAL_CRC32(crc, foldstr, foldlen);
43
44 size -= srclen;
45 p += srclen;
46 }
47 FIN_TRADITIONAL_CRC32(crc);
48 return (unsigned int) crc;
49}
50
51#else
52
53unsigned int
54ltree_crc32_sz(const char *buf, int size)
55{
56 pg_crc32 crc;
57 const char *p = buf;
58
59 INIT_TRADITIONAL_CRC32(crc);
60 while (size > 0)
61 {
62 COMP_TRADITIONAL_CRC32(crc, p, 1);
63 size--;
64 p++;
65 }
66 FIN_TRADITIONAL_CRC32(crc);
67 return (unsigned int) crc;
68}
69
70#endif /* !LOWER_NODE */
71