Skip to content

Commit

Permalink
deps: update ada to 2.4.1
Browse files Browse the repository at this point in the history
PR-URL: nodejs#48036
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
Reviewed-By: Matthew Aitken <maitken033380023@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
  • Loading branch information
nodejs-github-bot authored and anonrig committed Jul 9, 2023
1 parent 461c1e9 commit 5931018
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 55 deletions.
146 changes: 114 additions & 32 deletions deps/ada/ada.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* auto-generated on 2023-05-08 12:41:03 -0400. Do not edit! */
/* auto-generated on 2023-05-16 13:48:47 -0400. Do not edit! */
/* begin file src/ada.cpp */
#include "ada.h"
/* begin file src/checkers.cpp */
Expand Down Expand Up @@ -9786,6 +9786,11 @@ std::string to_unicode(std::string_view input) {
ADA_POP_DISABLE_WARNINGS

#include <algorithm>
#if ADA_NEON
#include <arm_neon.h>
#elif ADA_SSE2
#include <emmintrin.h>
#endif

namespace ada::unicode {

Expand Down Expand Up @@ -9817,8 +9822,58 @@ constexpr bool to_lower_ascii(char* input, size_t length) noexcept {
}
return non_ascii == 0;
}

ada_really_inline constexpr bool has_tabs_or_newline(
#if ADA_NEON
ada_really_inline bool has_tabs_or_newline(
std::string_view user_input) noexcept {
size_t i = 0;
const uint8x16_t mask1 = vmovq_n_u8('\r');
const uint8x16_t mask2 = vmovq_n_u8('\n');
const uint8x16_t mask3 = vmovq_n_u8('\t');
uint8x16_t running{0};
for (; i + 15 < user_input.size(); i += 16) {
uint8x16_t word = vld1q_u8((const uint8_t*)user_input.data() + i);
running = vorrq_u8(vorrq_u8(running, vorrq_u8(vceqq_u8(word, mask1),
vceqq_u8(word, mask2))),
vceqq_u8(word, mask3));
}
if (i < user_input.size()) {
uint8_t buffer[16]{};
memcpy(buffer, user_input.data() + i, user_input.size() - i);
uint8x16_t word = vld1q_u8((const uint8_t*)user_input.data() + i);
running = vorrq_u8(vorrq_u8(running, vorrq_u8(vceqq_u8(word, mask1),
vceqq_u8(word, mask2))),
vceqq_u8(word, mask3));
}
return vmaxvq_u8(running) != 0;
}
#elif ADA_SSE2
ada_really_inline bool has_tabs_or_newline(
std::string_view user_input) noexcept {
size_t i = 0;
const __m128i mask1 = _mm_set1_epi8('\r');
const __m128i mask2 = _mm_set1_epi8('\n');
const __m128i mask3 = _mm_set1_epi8('\t');
__m128i running{0};
for (; i + 15 < user_input.size(); i += 16) {
__m128i word = _mm_loadu_si128((const __m128i*)(user_input.data() + i));
running = _mm_or_si128(
_mm_or_si128(running, _mm_or_si128(_mm_cmpeq_epi8(word, mask1),
_mm_cmpeq_epi8(word, mask2))),
_mm_cmpeq_epi8(word, mask3));
}
if (i < user_input.size()) {
uint8_t buffer[16]{};
memcpy(buffer, user_input.data() + i, user_input.size() - i);
__m128i word = _mm_loadu_si128((const __m128i*)buffer);
running = _mm_or_si128(
_mm_or_si128(running, _mm_or_si128(_mm_cmpeq_epi8(word, mask1),
_mm_cmpeq_epi8(word, mask2))),
_mm_cmpeq_epi8(word, mask3));
}
return _mm_movemask_epi8(running) != 0;
}
#else
ada_really_inline bool has_tabs_or_newline(
std::string_view user_input) noexcept {
auto has_zero_byte = [](uint64_t v) {
return ((v - 0x0101010101010101) & ~(v)&0x8080808080808080);
Expand Down Expand Up @@ -9849,6 +9904,7 @@ ada_really_inline constexpr bool has_tabs_or_newline(
}
return running;
}
#endif

// A forbidden host code point is U+0000 NULL, U+0009 TAB, U+000A LF, U+000D CR,
// U+0020 SPACE, U+0023 (#), U+002F (/), U+003A (:), U+003C (<), U+003E (>),
Expand Down Expand Up @@ -13732,8 +13788,11 @@ bool url_aggregator::set_hostname(const std::string_view input) {

[[nodiscard]] std::string_view url_aggregator::get_host() const noexcept {
ada_log("url_aggregator::get_host");
// Technically, we should check if there is a hostname, but
// the code below works even if there isn't.
// if(!has_hostname()) { return ""; }
size_t start = components.host_start;
if (buffer.size() > components.host_start &&
if (components.host_end > components.host_start &&
buffer[components.host_start] == '@') {
start++;
}
Expand All @@ -13747,9 +13806,12 @@ bool url_aggregator::set_hostname(const std::string_view input) {

[[nodiscard]] std::string_view url_aggregator::get_hostname() const noexcept {
ada_log("url_aggregator::get_hostname");
// Technically, we should check if there is a hostname, but
// the code below works even if there isn't.
// if(!has_hostname()) { return ""; }
size_t start = components.host_start;
// So host_start is not where the host begins.
if (buffer.size() > components.host_start &&
if (components.host_end > components.host_start &&
buffer[components.host_start] == '@') {
start++;
}
Expand Down Expand Up @@ -14807,17 +14869,32 @@ struct ada_url_components {
uint32_t hash_start;
};

ada_url ada_parse(const char* input) noexcept {
ada_url ada_parse(const char* input, size_t length) noexcept {
return new ada::result<ada::url_aggregator>(
ada::parse<ada::url_aggregator>(input));
ada::parse<ada::url_aggregator>(std::string_view(input, length)));
}

bool ada_can_parse(const char* input, const char* base) noexcept {
if (base == nullptr) {
return ada::can_parse(input);
ada_url ada_parse_with_base(const char* input, size_t input_length,
const char* base, size_t base_length) noexcept {
auto base_out =
ada::parse<ada::url_aggregator>(std::string_view(base, base_length));

if (!base_out) {
return new ada::result<ada::url_aggregator>(base_out);
}
std::string_view sv(base);
return ada::can_parse(input, &sv);

return new ada::result<ada::url_aggregator>(ada::parse<ada::url_aggregator>(
std::string_view(input, input_length), &base_out.value()));
}

bool ada_can_parse(const char* input, size_t length) noexcept {
return ada::can_parse(std::string_view(input, length));
}

bool ada_can_parse_with_base(const char* input, size_t input_length,
const char* base, size_t base_length) noexcept {
auto base_view = std::string_view(base, base_length);
return ada::can_parse(std::string_view(input, input_length), &base_view);
}

void ada_free(ada_url result) noexcept {
Expand Down Expand Up @@ -14943,81 +15020,86 @@ ada_string ada_get_protocol(ada_url result) noexcept {
return ada_string_create(out.data(), out.length());
}

bool ada_set_href(ada_url result, const char* input) noexcept {
bool ada_set_href(ada_url result, const char* input, size_t length) noexcept {
ada::result<ada::url_aggregator>& r = get_instance(result);
if (!r) {
return false;
}
return r->set_href(input);
return r->set_href(std::string_view(input, length));
}

bool ada_set_host(ada_url result, const char* input) noexcept {
bool ada_set_host(ada_url result, const char* input, size_t length) noexcept {
ada::result<ada::url_aggregator>& r = get_instance(result);
if (!r) {
return false;
}
return r->set_host(input);
return r->set_host(std::string_view(input, length));
}

bool ada_set_hostname(ada_url result, const char* input) noexcept {
bool ada_set_hostname(ada_url result, const char* input,
size_t length) noexcept {
ada::result<ada::url_aggregator>& r = get_instance(result);
if (!r) {
return false;
}
return r->set_hostname(input);
return r->set_hostname(std::string_view(input, length));
}

bool ada_set_protocol(ada_url result, const char* input) noexcept {
bool ada_set_protocol(ada_url result, const char* input,
size_t length) noexcept {
ada::result<ada::url_aggregator>& r = get_instance(result);
if (!r) {
return false;
}
return r->set_protocol(input);
return r->set_protocol(std::string_view(input, length));
}

bool ada_set_username(ada_url result, const char* input) noexcept {
bool ada_set_username(ada_url result, const char* input,
size_t length) noexcept {
ada::result<ada::url_aggregator>& r = get_instance(result);
if (!r) {
return false;
}
return r->set_username(input);
return r->set_username(std::string_view(input, length));
}

bool ada_set_password(ada_url result, const char* input) noexcept {
bool ada_set_password(ada_url result, const char* input,
size_t length) noexcept {
ada::result<ada::url_aggregator>& r = get_instance(result);
if (!r) {
return false;
}
return r->set_password(input);
return r->set_password(std::string_view(input, length));
}

bool ada_set_port(ada_url result, const char* input) noexcept {
bool ada_set_port(ada_url result, const char* input, size_t length) noexcept {
ada::result<ada::url_aggregator>& r = get_instance(result);
if (!r) {
return false;
}
return r->set_port(input);
return r->set_port(std::string_view(input, length));
}

bool ada_set_pathname(ada_url result, const char* input) noexcept {
bool ada_set_pathname(ada_url result, const char* input,
size_t length) noexcept {
ada::result<ada::url_aggregator>& r = get_instance(result);
if (!r) {
return false;
}
return r->set_pathname(input);
return r->set_pathname(std::string_view(input, length));
}

void ada_set_search(ada_url result, const char* input) noexcept {
void ada_set_search(ada_url result, const char* input, size_t length) noexcept {
ada::result<ada::url_aggregator>& r = get_instance(result);
if (r) {
r->set_search(input);
r->set_search(std::string_view(input, length));
}
}

void ada_set_hash(ada_url result, const char* input) noexcept {
void ada_set_hash(ada_url result, const char* input, size_t length) noexcept {
ada::result<ada::url_aggregator>& r = get_instance(result);
if (r) {
r->set_hash(input);
r->set_hash(std::string_view(input, length));
}
}

Expand Down
32 changes: 23 additions & 9 deletions deps/ada/ada.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* auto-generated on 2023-05-08 12:41:03 -0400. Do not edit! */
/* auto-generated on 2023-05-16 13:48:47 -0400. Do not edit! */
/* begin file include/ada.h */
/**
* @file ada.h
Expand Down Expand Up @@ -468,6 +468,17 @@ namespace ada {
if (!(COND)) __builtin_unreachable(); \
} while (0)
#endif

#if defined(__SSE2__) || defined(__x86_64__) || defined(__x86_64) || \
(defined(_M_AMD64) || defined(_M_X64) || \
(defined(_M_IX86_FP) && _M_IX86_FP == 2))
#define ADA_SSE2 1
#endif

#if defined(__aarch64__) || defined(_M_ARM64)
#define ADA_NEON 1
#endif

#endif // ADA_COMMON_DEFS_H
/* end file include/ada/common_defs.h */
#include <stdint.h>
Expand Down Expand Up @@ -4320,7 +4331,7 @@ std::string to_unicode(std::string_view input);
* @attention The has_tabs_or_newline function is a bottleneck and it is simple
* enough that compilers like GCC can 'autovectorize it'.
*/
ada_really_inline constexpr bool has_tabs_or_newline(
ada_really_inline bool has_tabs_or_newline(
std::string_view user_input) noexcept;

/**
Expand Down Expand Up @@ -6473,14 +6484,14 @@ inline std::ostream &operator<<(std::ostream &out,
#ifndef ADA_ADA_VERSION_H
#define ADA_ADA_VERSION_H

#define ADA_VERSION "2.4.0"
#define ADA_VERSION "2.4.1"

namespace ada {

enum {
ADA_VERSION_MAJOR = 2,
ADA_VERSION_MINOR = 4,
ADA_VERSION_REVISION = 0,
ADA_VERSION_REVISION = 1,
};

} // namespace ada
Expand Down Expand Up @@ -6508,11 +6519,11 @@ using result = tl::expected<result_type, ada::errors>;

/**
* The URL parser takes a scalar value string input, with an optional null or
* base URL base (default null). The parser assumes the input has an UTF-8
* encoding.
* base URL base (default null). The parser assumes the input is a valid ASCII
* or UTF-8 string.
*
* @param input the string input to analyze.
* @param base_url the optional string input to use as a base url.
* @param input the string input to analyze (must be valid ASCII or UTF-8)
* @param base_url the optional URL input to use as a base url.
* @return a parsed URL.
*/
template <class result_type = ada::url_aggregator>
Expand All @@ -6525,14 +6536,17 @@ extern template ada::result<url_aggregator> parse<url_aggregator>(
std::string_view input, const url_aggregator* base_url);

/**
* Verifies whether the URL strings can be parsed. The function assumes
* that the inputs are valid ASCII or UTF-8 strings.
* @see https://url.spec.whatwg.org/#dom-url-canparse
* @return If URL can be parsed or not.
*/
bool can_parse(std::string_view input,
const std::string_view* base_input = nullptr);

/**
* Computes a href string from a file path.
* Computes a href string from a file path. The function assumes
* that the input is a valid ASCII or UTF-8 string.
* @return a href string (starts with file:://)
*/
std::string href_from_file(std::string_view path);
Expand Down
Loading

0 comments on commit 5931018

Please sign in to comment.