File tree Expand file tree Collapse file tree 4 files changed +51
-68
lines changed Expand file tree Collapse file tree 4 files changed +51
-68
lines changed Original file line number Diff line number Diff line change 192
192
'src/spawn_sync.cc' ,
193
193
'src/string_bytes.cc' ,
194
194
'src/string_search.cc' ,
195
- 'src/string_utils.cc' ,
196
195
'src/stream_base.cc' ,
197
196
'src/stream_wrap.cc' ,
198
197
'src/tcp_wrap.cc' ,
629
628
'<(OBJ_PATH)<(OBJ_SEPARATOR)util.<(OBJ_SUFFIX)' ,
630
629
'<(OBJ_PATH)<(OBJ_SEPARATOR)string_bytes.<(OBJ_SUFFIX)' ,
631
630
'<(OBJ_PATH)<(OBJ_SEPARATOR)string_search.<(OBJ_SUFFIX)' ,
632
- '<(OBJ_PATH)<(OBJ_SEPARATOR)string_utils.<(OBJ_SUFFIX)' ,
633
631
'<(OBJ_PATH)<(OBJ_SEPARATOR)stream_base.<(OBJ_SUFFIX)' ,
634
632
'<(OBJ_PATH)<(OBJ_SEPARATOR)node_constants.<(OBJ_SUFFIX)' ,
635
633
'<(OBJ_PATH)<(OBJ_SEPARATOR)node_revert.<(OBJ_SUFFIX)' ,
Original file line number Diff line number Diff line change @@ -131,10 +131,6 @@ enum url_error_cb_args {
131
131
return str.length () >= 2 && name (str[0 ], str[1 ]); \
132
132
}
133
133
134
- CHAR_TEST (8 , IsLowerCaseASCII, (ch >=' a' && ch <= ' z' ))
135
-
136
- CHAR_TEST (8 , IsLowerCaseASCII, (ch >=' a' && ch <= ' z' ))
137
-
138
134
// https://infra.spec.whatwg.org/#ascii-tab-or-newline
139
135
CHAR_TEST (8 , IsASCIITabOrNewline, (ch == ' \t ' || ch == ' \n ' || ch == ' \r ' ))
140
136
@@ -865,9 +861,7 @@ static url_host_type ParseHost(url_host* host,
865
861
if (!stringutils::ContainsNonAscii (buf, strlen (buf))) {
866
862
// Lowercase ASCII domains
867
863
for (size_t n = 0 ; n < decoded.size (); n++) {
868
- if (!IsLowerCaseASCII (decoded[n])) {
869
- decoded[n] = ASCIILowercase (decoded[n]);
870
- }
864
+ decoded[n] = ASCIILowercase (decoded[n]);
871
865
}
872
866
} else {
873
867
// Then we have to Unicode IDNA toASCII
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 2
2
#ifndef SRC_STRING_UTILS_H_
3
3
#define SRC_STRING_UTILS_H_
4
4
5
- #include " env.h"
6
- #include " env-inl.h"
7
- #include " util.h"
5
+ #include < cstddef>
6
+ #include < cstdint>
8
7
9
8
namespace node {
10
9
namespace stringutils {
11
- bool ContainsNonAscii (const char * src, size_t len);
10
+ inline static bool contains_non_ascii_slow (const char * buf, size_t len) {
11
+ for (size_t i = 0 ; i < len; ++i) {
12
+ if (buf[i] & 0x80 )
13
+ return true ;
14
+ }
15
+ return false ;
16
+ }
17
+
18
+ inline bool ContainsNonAscii (const char * src, size_t len) {
19
+ if (len < 16 ) {
20
+ return contains_non_ascii_slow (src, len);
21
+ }
22
+
23
+ const unsigned bytes_per_word = sizeof (uintptr_t );
24
+ const unsigned align_mask = bytes_per_word - 1 ;
25
+ const unsigned unaligned = reinterpret_cast <uintptr_t >(src) & align_mask;
26
+
27
+ if (unaligned > 0 ) {
28
+ const unsigned n = bytes_per_word - unaligned;
29
+ if (contains_non_ascii_slow (src, n))
30
+ return true ;
31
+ src += n;
32
+ len -= n;
33
+ }
34
+
35
+
36
+ #if defined(_WIN64) || defined(_LP64)
37
+ const uintptr_t mask = 0x8080808080808080ll ;
38
+ #else
39
+ const uintptr_t mask = 0x80808080l ;
40
+ #endif
41
+
42
+ const uintptr_t * srcw = reinterpret_cast <const uintptr_t *>(src);
43
+
44
+ for (size_t i = 0 , n = len / bytes_per_word; i < n; ++i) {
45
+ if (srcw[i] & mask)
46
+ return true ;
47
+ }
48
+
49
+ const unsigned remainder = len & align_mask;
50
+ if (remainder > 0 ) {
51
+ const size_t offset = len - remainder;
52
+ if (contains_non_ascii_slow (src + offset, remainder))
53
+ return true ;
54
+ }
55
+
56
+ return false ;
57
+ }
12
58
} // namespace stringutils
13
59
} // namespace node
14
60
You can’t perform that action at this time.
0 commit comments