tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

htmlaccelNotInline.cpp (10467B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #include "mozilla/htmlaccel/htmlaccel.h"
      6 #include "mozilla/htmlaccel/htmlaccelNotInline.h"
      7 
      8 namespace mozilla::htmlaccel {
      9 
     10 // TODO: Perhaps inlining this one on aarch64 wouldn't run into the
     11 // LLVM LICM vs. regalloc bug. But then, inlining this would only
     12 // avoid the overhead of one function call and wouldn't reuse the
     13 // SIMD contants in a useful way.
     14 MOZ_NEVER_INLINE bool ContainsMarkup(const char16_t* aPtr,
     15                                     const char16_t* aEnd) {
     16  return detail::ContainsMarkup(aPtr, aEnd);
     17 }
     18 
     19 // HTML Serializer functions
     20 
     21 /// Skip over SIMD strides not containing less-than, greater-than, ampersand,
     22 /// and no-break space.
     23 MOZ_NEVER_INLINE size_t SkipNonEscapedInTextNode(const char16_t* aPtr,
     24                                                 const char16_t* aEnd) {
     25  return detail::AccelerateTextNode(aPtr, aEnd, detail::LT_GT_AMP_NBSP, true);
     26 }
     27 
     28 /// Skip over SIMD strides not containing less-than, greater-than, ampersand,
     29 /// and no-break space.
     30 MOZ_NEVER_INLINE size_t SkipNonEscapedInTextNode(const char* aPtr,
     31                                                 const char* aEnd) {
     32  return detail::AccelerateTextNode(aPtr, aEnd, detail::LT_GT_AMP_NBSP, true);
     33 }
     34 
     35 /// Skip over SIMD strides not containing less-than, greater-than, ampersand,
     36 /// no-break space, and double quote.
     37 MOZ_NEVER_INLINE size_t SkipNonEscapedInAttributeValue(const char16_t* aPtr,
     38                                                       const char16_t* aEnd) {
     39  return detail::AccelerateTextNode(aPtr, aEnd, detail::LT_GT_AMP_NBSP_QUOT,
     40                                    true);
     41 }
     42 
     43 /// Count occurrences of less-than, greater-than, ampersand, and no-break space.
     44 MOZ_NEVER_INLINE uint32_t CountEscapedInTextNode(const char16_t* aPtr,
     45                                                 const char16_t* aEnd) {
     46  return detail::CountEscaped(aPtr, aEnd, false);
     47 }
     48 
     49 /// Count occurrences of less-than, greater-than, ampersand, and no-break space.
     50 MOZ_NEVER_INLINE uint32_t CountEscapedInTextNode(const char* aPtr,
     51                                                 const char* aEnd) {
     52  return detail::CountEscaped(aPtr, aEnd, false);
     53 }
     54 
     55 /// Count occurrences of less-than, greater-than, ampersand, no-break space, and
     56 /// double quote.
     57 MOZ_NEVER_INLINE uint32_t CountEscapedInAttributeValue(const char16_t* aPtr,
     58                                                       const char16_t* aEnd) {
     59  return detail::CountEscaped(aPtr, aEnd, true);
     60 }
     61 
     62 // HTML Tokenizer functions
     63 //
     64 // The "Fastest" cases don't count line numbers and, therefore, don't need
     65 // to be sensitive to line feeds. "ViewSource" and "LineCol" count line
     66 // numbers and, therefore, care about line feeds.
     67 //
     68 // Even the "Fastest" case needs to care about carriage returns in order
     69 // to be able to normalize CR and CRLF to an LF. (CRLF to LF ends up
     70 // finding the LF without SIMD once the CR has been detected using SIMD.)
     71 //
     72 // The three boolean arguments and their defaults are:
     73 // bool aAllowSurrogates = true,
     74 // bool aAllowHyphen = true,
     75 // bool aAllowRightSquareBracket = true,
     76 //
     77 // Parsing from network (the `LineCol` cases) sets aAllowSurrogates
     78 // to false in order to count column numbers by scalar values instead
     79 // of UTF-16 code unit.
     80 //
     81 // The hyphen and the right square bracket share the low 4 bits (0xD)
     82 // with the carriage return, so they need to be special-cased and can't
     83 // be covered byt the lookup table that's used for other characters
     84 // of interest, since the lookup table already needs to contain CR.
     85 
     86 /// The innerHTML / DOMParser case for the data state in the HTML parser
     87 MOZ_NEVER_INLINE int32_t AccelerateDataFastest(const char16_t* aPtr,
     88                                               const char16_t* aEnd) {
     89  return detail::AccelerateTextNode(aPtr, aEnd, detail::ZERO_LT_AMP_CR, true);
     90 }
     91 
     92 /// View Source case for the data state in the HTML parser
     93 MOZ_NEVER_INLINE int32_t AccelerateDataViewSource(const char16_t* aPtr,
     94                                                  const char16_t* aEnd) {
     95  return detail::AccelerateTextNode(aPtr, aEnd, detail::ZERO_LT_AMP_CR_LF,
     96                                    true);
     97 }
     98 
     99 /// Normal network case for the data state in the HTML parser
    100 MOZ_NEVER_INLINE int32_t AccelerateDataLineCol(const char16_t* aPtr,
    101                                               const char16_t* aEnd) {
    102  return detail::AccelerateTextNode(aPtr, aEnd, detail::ZERO_LT_AMP_CR_LF,
    103                                    false);
    104 }
    105 
    106 /// The innerHTML / DOMParser case for the RAWTEXT state in the HTML parser
    107 MOZ_NEVER_INLINE int32_t AccelerateRawtextFastest(const char16_t* aPtr,
    108                                                  const char16_t* aEnd) {
    109  return detail::AccelerateTextNode(aPtr, aEnd, detail::ZERO_LT_CR, true);
    110 }
    111 
    112 /// View Source case for the RAWTEXT state in the HTML parser
    113 MOZ_NEVER_INLINE int32_t AccelerateRawtextViewSource(const char16_t* aPtr,
    114                                                     const char16_t* aEnd) {
    115  return detail::AccelerateTextNode(aPtr, aEnd, detail::ZERO_LT_CR_LF, true);
    116 }
    117 
    118 /// Normal network case for the RAWTEXT state in the HTML parser
    119 MOZ_NEVER_INLINE int32_t AccelerateRawtextLineCol(const char16_t* aPtr,
    120                                                  const char16_t* aEnd) {
    121  return detail::AccelerateTextNode(aPtr, aEnd, detail::ZERO_LT_CR_LF, false);
    122 }
    123 
    124 /// The innerHTML / DOMParser case for the comment state in the HTML parser
    125 MOZ_NEVER_INLINE int32_t AccelerateCommentFastest(const char16_t* aPtr,
    126                                                  const char16_t* aEnd) {
    127  return detail::AccelerateTextNode(aPtr, aEnd, detail::ZERO_LT_CR, true,
    128                                    false);
    129 }
    130 
    131 /// View Source case for the comment state in the HTML parser
    132 MOZ_NEVER_INLINE int32_t AccelerateCommentViewSource(const char16_t* aPtr,
    133                                                     const char16_t* aEnd) {
    134  return detail::AccelerateTextNode(aPtr, aEnd, detail::ZERO_LT_CR_LF, true,
    135                                    false);
    136 }
    137 
    138 /// Normal network case for the comment state in the HTML parser
    139 MOZ_NEVER_INLINE int32_t AccelerateCommentLineCol(const char16_t* aPtr,
    140                                                  const char16_t* aEnd) {
    141  return detail::AccelerateTextNode(aPtr, aEnd, detail::ZERO_LT_CR_LF, false,
    142                                    false);
    143 }
    144 
    145 /// The innerHTML / DOMParser case for the attribute value single-quoted state
    146 /// in the HTML parser
    147 MOZ_NEVER_INLINE int32_t AccelerateAttributeValueSingleQuotedFastest(
    148    const char16_t* aPtr, const char16_t* aEnd) {
    149  return detail::AccelerateTextNode(aPtr, aEnd, detail::ZERO_APOS_AMP_CR, true);
    150 }
    151 
    152 /// View Source case for the attribute value single-quoted state in the HTML
    153 /// parser
    154 MOZ_NEVER_INLINE int32_t AccelerateAttributeValueSingleQuotedViewSource(
    155    const char16_t* aPtr, const char16_t* aEnd) {
    156  return detail::AccelerateTextNode(aPtr, aEnd, detail::ZERO_APOS_AMP_CR_LF,
    157                                    true);
    158 }
    159 
    160 /// Normal network case for the attribute value single-quoted state in the HTML
    161 /// parser
    162 MOZ_NEVER_INLINE int32_t AccelerateAttributeValueSingleQuotedLineCol(
    163    const char16_t* aPtr, const char16_t* aEnd) {
    164  return detail::AccelerateTextNode(aPtr, aEnd, detail::ZERO_APOS_AMP_CR_LF,
    165                                    false);
    166 }
    167 
    168 /// The innerHTML / DOMParser case for the attribute value double-quoted state
    169 /// in the HTML parser
    170 MOZ_NEVER_INLINE int32_t AccelerateAttributeValueDoubleQuotedFastest(
    171    const char16_t* aPtr, const char16_t* aEnd) {
    172  return detail::AccelerateTextNode(aPtr, aEnd, detail::ZERO_QUOT_AMP_CR, true);
    173 }
    174 
    175 /// View Source case for the attribute value double-quoted state in the HTML
    176 /// parser
    177 MOZ_NEVER_INLINE int32_t AccelerateAttributeValueDoubleQuotedViewSource(
    178    const char16_t* aPtr, const char16_t* aEnd) {
    179  return detail::AccelerateTextNode(aPtr, aEnd, detail::ZERO_QUOT_AMP_CR_LF,
    180                                    true);
    181 }
    182 
    183 /// Normal network case for the attribute value double-quoted state in the HTML
    184 /// parser
    185 MOZ_NEVER_INLINE int32_t AccelerateAttributeValueDoubleQuotedLineCol(
    186    const char16_t* aPtr, const char16_t* aEnd) {
    187  return detail::AccelerateTextNode(aPtr, aEnd, detail::ZERO_QUOT_AMP_CR_LF,
    188                                    false);
    189 }
    190 
    191 /// The innerHTML / DOMParser case for the CDATA section state in the HTML
    192 /// parser
    193 MOZ_NEVER_INLINE int32_t AccelerateCdataSectionFastest(const char16_t* aPtr,
    194                                                       const char16_t* aEnd) {
    195  return detail::AccelerateTextNode(aPtr, aEnd, detail::ZERO_CR, true, true,
    196                                    false);
    197 }
    198 
    199 /// View Source case for the CDATA section state in the HTML parser
    200 MOZ_NEVER_INLINE int32_t
    201 AccelerateCdataSectionViewSource(const char16_t* aPtr, const char16_t* aEnd) {
    202  return detail::AccelerateTextNode(aPtr, aEnd, detail::ZERO_CR_LF, true, true,
    203                                    false);
    204 }
    205 
    206 /// Normal network case for the CDATA section state in the HTML parser
    207 MOZ_NEVER_INLINE int32_t AccelerateCdataSectionLineCol(const char16_t* aPtr,
    208                                                       const char16_t* aEnd) {
    209  return detail::AccelerateTextNode(aPtr, aEnd, detail::ZERO_CR_LF, false, true,
    210                                    false);
    211 }
    212 
    213 /// The innerHTML / DOMParser case for the plaintext state in the HTML parser
    214 MOZ_NEVER_INLINE int32_t AcceleratePlaintextFastest(const char16_t* aPtr,
    215                                                    const char16_t* aEnd) {
    216  return detail::AccelerateTextNode(aPtr, aEnd, detail::ZERO_CR, true);
    217 }
    218 
    219 /// View Source case for the plaintext state in the HTML parser
    220 MOZ_NEVER_INLINE int32_t AcceleratePlaintextViewSource(const char16_t* aPtr,
    221                                                       const char16_t* aEnd) {
    222  return detail::AccelerateTextNode(aPtr, aEnd, detail::ZERO_CR_LF, true);
    223 }
    224 
    225 /// Normal network case for the plaintext state in the HTML parser
    226 MOZ_NEVER_INLINE int32_t AcceleratePlaintextLineCol(const char16_t* aPtr,
    227                                                    const char16_t* aEnd) {
    228  return detail::AccelerateTextNode(aPtr, aEnd, detail::ZERO_CR_LF, false);
    229 }
    230 
    231 }  // namespace mozilla::htmlaccel