| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: strspn.c,v 1.2 2018/02/04 01:13:45 mrg Exp $ */ | | 1 | /* $NetBSD: strspn.c,v 1.3 2023/06/18 22:18:13 rillig Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2008 Joerg Sonnenberger | | 4 | * Copyright (c) 2008 Joerg Sonnenberger |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -16,27 +16,27 @@ | | | @@ -16,27 +16,27 @@ |
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR | | 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR |
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, | | 19 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | | 26 | */ |
27 | | | 27 | |
28 | #include <sys/cdefs.h> | | 28 | #include <sys/cdefs.h> |
29 | __RCSID("$NetBSD: strspn.c,v 1.2 2018/02/04 01:13:45 mrg Exp $"); | | 29 | __RCSID("$NetBSD: strspn.c,v 1.3 2023/06/18 22:18:13 rillig Exp $"); |
30 | | | 30 | |
31 | #if !defined(_KERNEL) && !defined(_STANDALONE) | | 31 | #if !defined(_KERNEL) && !defined(_STANDALONE) |
32 | #include <assert.h> | | 32 | #include <assert.h> |
33 | #include <inttypes.h> | | 33 | #include <inttypes.h> |
34 | #include <limits.h> | | 34 | #include <limits.h> |
35 | #include <string.h> | | 35 | #include <string.h> |
36 | #else | | 36 | #else |
37 | #include <lib/libkern/libkern.h> | | 37 | #include <lib/libkern/libkern.h> |
38 | #endif | | 38 | #endif |
39 | | | 39 | |
40 | #if ULONG_MAX != 0xffffffffffffffffull | | 40 | #if ULONG_MAX != 0xffffffffffffffffull |
41 | | | 41 | |
42 | size_t | | 42 | size_t |
| @@ -104,27 +104,27 @@ strspn_x(const char *s_s, const char *ch | | | @@ -104,27 +104,27 @@ strspn_x(const char *s_s, const char *ch |
104 | m_c |= bit; | | 104 | m_c |= bit; |
105 | } | | 105 | } |
106 | } | | 106 | } |
107 | | | 107 | |
108 | /* For strcspn() we just invert the validity set */ | | 108 | /* For strcspn() we just invert the validity set */ |
109 | m_0 ^= invert; | | 109 | m_0 ^= invert; |
110 | m_4 ^= invert; | | 110 | m_4 ^= invert; |
111 | m_8 ^= invert; | | 111 | m_8 ^= invert; |
112 | m_c ^= invert; | | 112 | m_c ^= invert; |
113 | | | 113 | |
114 | /* | | 114 | /* |
115 | * We could do remove the lsb from m_0 to terminate at the | | 115 | * We could do remove the lsb from m_0 to terminate at the |
116 | * end of the input string. | | 116 | * end of the input string. |
117 | * However prefetching the next char is benifitial and we must | | 117 | * However prefetching the next char is beneficial and we must |
118 | * not read the byte after the \0 - as it might fault! | | 118 | * not read the byte after the \0 - as it might fault! |
119 | * So we take the 'hit' of the compare against 0. | | 119 | * So we take the 'hit' of the compare against 0. |
120 | */ | | 120 | */ |
121 | | | 121 | |
122 | ch = *s++; | | 122 | ch = *s++; |
123 | for (count = 0; ch != 0; ch = next_ch) { | | 123 | for (count = 0; ch != 0; ch = next_ch) { |
124 | next_ch = s[count]; | | 124 | next_ch = s[count]; |
125 | if (__predict_true(ch < 0x80)) { | | 125 | if (__predict_true(ch < 0x80)) { |
126 | check = m_0; | | 126 | check = m_0; |
127 | if (ch >= 0x40) | | 127 | if (ch >= 0x40) |
128 | check = m_4; | | 128 | check = m_4; |
129 | } else { | | 129 | } else { |
130 | check = m_8; | | 130 | check = m_8; |