diff --git a/src/workerd/api/data-url.c++ b/src/workerd/api/data-url.c++ index 358f094a8d1..b8341355c86 100644 --- a/src/workerd/api/data-url.c++ +++ b/src/workerd/api/data-url.c++ @@ -1,5 +1,6 @@ #include "data-url.h" #include +#include namespace workerd::api { @@ -21,12 +22,16 @@ 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 constexpr std::array ascii_whitespace_table = []() consteval { + std::array result{}; + for (uint8_t c : { 0x09, 0x0a, 0x0c, 0x0d, 0x20 }) { + result[c] = true; + } + return result; + }(); + + static constexpr auto isAsciiWhitespace = [](uint8_t c) { + return ascii_whitespace_table[c]; }; static const auto trim = [](auto label) { diff --git a/src/workerd/api/form-data.c++ b/src/workerd/api/form-data.c++ index 47e2f2352ad..e56fb40f8ce 100644 --- a/src/workerd/api/form-data.c++ +++ b/src/workerd/api/form-data.c++ @@ -84,11 +84,11 @@ void parseFormData(kj::Maybe js, kj::Vector& data, 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 {