/src/spotify-json/include/spotify/json/detail/skip_chars.hpp
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2015-2016 Spotify AB |
3 | | * |
4 | | * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
5 | | * use this file except in compliance with the License. You may obtain a copy of |
6 | | * the License at |
7 | | * |
8 | | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | | * |
10 | | * Unless required by applicable law or agreed to in writing, software |
11 | | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
12 | | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
13 | | * License for the specific language governing permissions and limitations under |
14 | | * the License. |
15 | | */ |
16 | | |
17 | | #pragma once |
18 | | |
19 | | #include <spotify/json/decode_context.hpp> |
20 | | #include <spotify/json/detail/macros.hpp> |
21 | | |
22 | | namespace spotify { |
23 | | namespace json { |
24 | | namespace detail { |
25 | | |
26 | | void skip_any_simple_characters_scalar(decode_context &context); |
27 | | #if defined(json_arch_x86_sse42) |
28 | | void skip_any_simple_characters_sse42(decode_context &context); |
29 | | #endif // defined(json_arch_x86_sse42) |
30 | | |
31 | | /** |
32 | | * Skip past the bytes of the string until either a " or a \ character is |
33 | | * found. This method attempts to skip as large chunks of memory as possible |
34 | | * at each step, by making sure that the context position is aligned to the |
35 | | * appropriate address and then reading and comparing several bytes in a |
36 | | * single read operation. |
37 | | */ |
38 | 103k | json_force_inline void skip_any_simple_characters(decode_context &context) { |
39 | 103k | #if defined(json_arch_x86_sse42) |
40 | 103k | if (json_likely(context.has_sse42)) { |
41 | 103k | return skip_any_simple_characters_sse42(context); |
42 | 103k | } |
43 | 0 | #endif // defined(json_arch_x86_sse42) |
44 | 0 | return skip_any_simple_characters_scalar(context); |
45 | 103k | } |
46 | | |
47 | | void skip_any_whitespace_scalar(decode_context &context); |
48 | | #if defined(json_arch_x86_sse42) |
49 | | void skip_any_whitespace_sse42(decode_context &context); |
50 | | #endif // defined(json_arch_x86_sse42) |
51 | | |
52 | | /** |
53 | | * Skip past the bytes of the string until a non-whitespace character is |
54 | | * found. This method attempts to skip as large chunks of memory as possible |
55 | | * at each step, by making sure that the context position is aligned to the |
56 | | * appropriate address and then reading and comparing several bytes in a |
57 | | * single read operation. |
58 | | */ |
59 | 1.24M | json_force_inline void skip_any_whitespace(decode_context &context) { |
60 | | #if defined(json_arch_x86_sse42) |
61 | | if (json_likely(context.has_sse42)) { |
62 | | return skip_any_whitespace_sse42(context); |
63 | | } |
64 | | #endif // defined(json_arch_x86_sse42) |
65 | 1.24M | skip_any_whitespace_scalar(context); |
66 | 1.24M | } |
67 | | |
68 | | } // namespace detail |
69 | | } // namespace json |
70 | | } // namespace spotify |