diff --git a/src/workerd/api/data-url.c++ b/src/workerd/api/data-url.c++ index 5fa6a623d22..da1afae94bd 100644 --- a/src/workerd/api/data-url.c++ +++ b/src/workerd/api/data-url.c++ @@ -10,6 +10,18 @@ kj::Maybe DataUrl::tryParse(kj::StringPtr url) { return kj::none; } +static constexpr kj::FixedArray ascii_whitespace_table = []() consteval { + kj::FixedArray result{}; + for (uint8_t c: {0x09, 0x0a, 0x0c, 0x0d, 0x20}) { + result[c] = true; + } + return result; +}(); + +constexpr bool isAsciiWhitespace(uint8_t c) noexcept { + return ascii_whitespace_table[c]; +} + kj::Maybe DataUrl::from(const jsg::Url& url) { if (url.getProtocol() != "data:"_kj) return kj::none; auto clone = url.clone(jsg::Url::EquivalenceOption::IGNORE_FRAGMENTS); @@ -21,11 +33,6 @@ kj::Maybe DataUrl::from(const jsg::Url& url) { // Per the fetch spec, it doesn't matter if the comma is within a quoted // string value in the MIME type... which is fun. - static const auto isAsciiWhitespace = [](auto c) { - return c == 0x09 /* tab */ || c == 0x0a /* lf */ || c == 0x0c /* ff */ || - c == 0x0d /* cr */ || c == 0x20 /* sp */; - }; - static const auto trim = [](auto label) { size_t start = 0; auto end = label.size(); diff --git a/src/workerd/api/form-data.c++ b/src/workerd/api/form-data.c++ index 75cc8fad68c..7c209e138d0 100644 --- a/src/workerd/api/form-data.c++ +++ b/src/workerd/api/form-data.c++ @@ -86,11 +86,11 @@ void parseFormData(kj::Maybe js, const auto done = [](kj::ArrayPtr& body) { // Consume any (CR)LF characters that trailed the boundary and indicate continuation, or consume // the terminal "--" characters and indicate termination, or throw an error. - if (startsWith(body, "\n")) { + if (startsWith(body, "\n"_kj)) { body = body.slice(1, body.size()); - } else if (startsWith(body, "\r\n")) { + } else if (startsWith(body, "\r\n"_kj)) { body = body.slice(2, body.size()); - } else if (startsWith(body, "--")) { + } else if (startsWith(body, "--"_kj)) { // We're done! return true; } else { diff --git a/src/workerd/util/mimetype.c++ b/src/workerd/util/mimetype.c++ index 495cc85442c..c33414307e8 100644 --- a/src/workerd/util/mimetype.c++ +++ b/src/workerd/util/mimetype.c++ @@ -6,7 +6,6 @@ #include #include #include -#include namespace workerd { @@ -16,8 +15,8 @@ constexpr bool isWhitespace(const char c) noexcept { return (c == '\r' || c == '\n' || c == '\t' || c == ' '); } -constexpr std::array token_table = []() consteval { - std::array result{}; +static constexpr kj::FixedArray token_table = []() consteval { + kj::FixedArray result{}; for (uint8_t c: {'!', '#', '$', '%', '&', '\'', '*', '+', '\\', '-', '.', '^', '_', '`', '|', '~'}) { @@ -46,8 +45,8 @@ constexpr bool isTokenChar(const uint8_t c) noexcept { return token_table[c]; } -constexpr std::array quoted_string_token_table = []() consteval { - std::array result{}; +static constexpr kj::FixedArray quoted_string_token_table = []() consteval { + kj::FixedArray result{}; result['\t'] = true; for (uint8_t c = 0x20; c <= 0x7e; c++) {