Darshan Sen
e045ddad54
src: fix return type of method in string_search.h
...
`Vector::forward()` is supposed to return a `bool`.
PR-URL: https://github.com/nodejs/node/pull/37167
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2021-02-10 18:56:08 +05:30
Darshan Sen
c148c3a008
src: fix warning in string_search.h
...
Fixes: https://github.com/nodejs/node/issues/37145
PR-URL: https://github.com/nodejs/node/pull/37146
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
2021-02-04 10:46:27 -08:00
Ben Noordhuis
d2e91778d9
src: fix -Wmaybe-uninitialized compiler warning
...
Turn the `strategy_` method pointer into an enum-based static dispatch.
It's both safer and more secure (no chance of method pointer corruption)
and it helps GCC see that the shift and suffix tables it's complaining
about are unused in single char search mode.
Fixes the following warning:
../src/string_search.h:113:30: warning:
‘search’ may be used uninitialized in this function [-Wmaybe-uninitialized]
return (this->*strategy_)(subject, index);
Fixes: https://github.com/nodejs/node/issues/26733
Refs: https://github.com/nodejs/node/pull/31532
Refs: https://github.com/nodejs/node/pull/31798
PR-URL: https://github.com/nodejs/node/pull/31809
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Richard Lau <riclau@uk.ibm.com >
Reviewed-By: Denys Otrishko <shishugi@gmail.com >
Reviewed-By: David Carlier <devnexen@gmail.com >
Reviewed-By: Sam Roberts <vieuxtech@gmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: James M Snell <jasnell@gmail.com >
2020-03-11 16:57:53 +01:00
gengjiawen
95e3119bad
src: remove redundant cast in string_search.h
...
PR-URL: https://github.com/nodejs/node/pull/26426
Reviewed-By: Richard Lau <riclau@uk.ibm.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
2019-03-07 00:31:39 +01:00
gengjiawen
8137668c53
src: apply clang-tidy rule modernize-deprecated-headers
...
PR-URL: https://github.com/nodejs/node/pull/26159
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2019-02-27 05:35:53 +01:00
Joyee Cheung
1838d00eba
src: reduce includes of node_internals.h
...
PR-URL: https://github.com/nodejs/node/pull/25507
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com >
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: James M Snell <jasnell@gmail.com >
2019-01-21 07:54:42 +01:00
Anna Henningsen
da13c44b0d
src: remove unused variable from string_search.h
...
PR-URL: https://github.com/nodejs/node/pull/25139
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: Richard Lau <riclau@uk.ibm.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
2018-12-30 19:45:14 -08:00
cjihrig
c2b4269b77
src: use DCHECK_* macros where possible
...
PR-URL: https://github.com/nodejs/node/pull/25207
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
2018-12-26 12:25:19 -05:00
Masashi Hirano
75f6ef9f6f
src: fix typo string_search.h comment
...
PR-URL: https://github.com/nodejs/node/pull/21115
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com >
Reviewed-By: Richard Lau <riclau@uk.ibm.com >
Reviewed-By: Jon Moss <me@jonathanmoss.me >
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com >
2018-06-04 00:52:56 +02:00
Anna Henningsen
945da6d22d
src: remove static variables from string_search
...
These variables can as well be stack-allocated. This avoids
relying on global state that is not protected by mutexes.
Thanks to Stephen Belanger for reviewing this change in its original PR.
Refs: https://github.com/ayojs/ayo/pull/82
PR-URL: https://github.com/nodejs/node/pull/20541
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
2018-05-09 20:18:27 +02:00
Anna Henningsen
987387534a
src: minor refactor to string_search.h
...
- Use `std::max` instead of a custom variant
- Use member method pointers to avoid an extra layer of indirection
- Stop transferring `Vector` into the `node` namespace
PR-URL: https://github.com/nodejs/node/pull/20546
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com >
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com >
2018-05-09 18:11:16 +02:00
Ben Noordhuis
0fdd88a374
module: speed up package.json parsing more
...
Move the logic from the previous commit to C++ land in order to avoid
creating a new string when we know we won't parse it anyway.
PR-URL: https://github.com/nodejs/node/pull/15767
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2017-11-15 12:01:20 +01:00
gitHubTracey
838eca2656
src: operator[] checks bounds in debug mode
...
PR-URL: https://github.com/nodejs/node/pull/16002
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Timothy Gu <timothygu99@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
2017-10-22 20:11:24 +02:00
Anna Henningsen
290315ace7
src: refactor #include handling
...
`node_internals.h` already includes the most common headers,
so double includes can be avoided in a lot of cases. Also don’t include
`node_internals.h` from `node.h` implicitly anymore, as that is mostly
unnecessary.
PR-URL: https://github.com/nodejs/node/pull/14697
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Refael Ackermann <refack@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2017-09-14 17:38:38 +02:00
Ben Noordhuis
1b7372f2fb
src: replace ASSERT with CHECK
...
Builds always have asserts enabled so there is no point distinguishing
between debug-only checks and run-time checks. Replace calls to ASSERT
and friends with their CHECK counterparts.
Fixes: https://github.com/nodejs/node/issues/14461
PR-URL: https://github.com/nodejs/node/pull/14474
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Nikolai Vavilov <vvnicholas@gmail.com >
Reviewed-By: XadillaX <admin@xcoder.in >
2017-07-27 17:11:08 +02:00
Benjamin Fleischer
4897ae2114
benchmark,build,doc,lib,src,test: correct typos
...
PR-URL: https://github.com/nodejs/node/pull/11189
Reviewed-By: Brian White <mscdex@mscdex.net >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com >
2017-03-03 16:29:19 -05:00
Ben Noordhuis
f8d3f6fbf4
src: remove obsolete NOLINT comments
...
Obsoleted by the recent cpplint upgrade.
PR-URL: https://github.com/nodejs/node/pull/7462
Reviewed-By: Trevor Norris <trev.norris@gmail.com >
2016-06-28 21:21:21 +02:00
Ben Noordhuis
0ba0eca986
src: fix readability/namespace cpplint warnings
...
PR-URL: https://github.com/nodejs/node/pull/7462
Reviewed-By: Trevor Norris <trev.norris@gmail.com >
2016-06-28 21:21:21 +02:00
Brian White
f914f37742
src: clean up string_search
...
This commit removes some unnecessary signed checks on unsigned
variables and removes a few unused private functions.
PR-URL: https://github.com/nodejs/node/pull/7174
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com >
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2016-06-14 16:10:21 -04:00
Ben Noordhuis
eff96d32dc
src: add include guards to internal headers
...
For consistency with the newly added src/base64.h header, check that
NODE_WANT_INTERNALS is defined and set in internal headers.
PR-URL: https://github.com/nodejs/node/pull/6948
Refs: https://github.com/nodejs/node/pull/6910
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Trevor Norris <trev.norris@gmail.com >
2016-05-25 09:54:24 +02:00
Anna Henningsen
bc8b525440
buffer: fix lastIndexOf index underflow issue
...
Fix `buffer.lastIndexOf()` for the case that the first character
of the needle is contained in the haystack, but in a location that
makes it impossible to be part of a full match.
For example, when searching for 'abc' in 'abcdef', only the 'cdef'
part needs to be searched for 'c', because earlier locations can
be excluded by index calculations alone.
Previously, such a search would result in an assertion failure.
This applies only to Node.js v6, as `lastIndexOf` was added in it.
PR-URL: https://github.com/nodejs/node/pull/6511
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Trevor Norris <trev.norris@gmail.com >
2016-05-04 22:14:29 +02:00
Anna Henningsen
bfe645d1f4
src: fix FindFirstCharacter argument alignment
...
PR-URL: https://github.com/nodejs/node/pull/6511
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Trevor Norris <trev.norris@gmail.com >
2016-05-04 22:14:20 +02:00
dcposch@dcpos.ch
6c1e5ad3ab
buffer: add Buffer.prototype.lastIndexOf()
...
* Remove unnecessary templating from SearchString
SearchString used to have separate PatternChar and SubjectChar template type
arguments, apparently to support things like searching for an 8-bit string
inside a 16-bit string or vice versa. However, SearchString is only used from
node_buffer.cc, where PatternChar and SubjectChar are always the same. Since
this is extra complexity that's unused and untested (simplifying to a single
Char template argument still compiles and didn't break any unit tests), I
removed it.
* Use Boyer-Hoore[-Horspool] for both indexOf and lastIndexOf
Add test cases for lastIndexOf. Test the fallback from BMH to
Boyer-Moore, which looks like it was totally untested before.
* Extra bounds checks in node_buffer.cc
* Extra asserts in string_search.h
* Buffer.lastIndexOf: clean up, enforce consistency w/ String.lastIndexOf
* Polyfill memrchr(3) for non-GNU systems
PR-URL: https://github.com/nodejs/node/pull/4846
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Trevor Norris <trev.norris@gmail.com >
2016-04-25 08:24:28 -07:00
Karl Skomski
a18dd7b788
src: replace naive search in Buffer::IndexOf
...
Adds the string search implementation from v8
which uses naive search if pattern length < 8
or to a specific badness then uses Boyer-Moore-Horspool
Added benchmark shows the expected improvements
Added option to use ucs2 encoding with Buffer::IndexOf
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Trevor Norris <trev.norris@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/2539
2015-10-07 21:09:53 -07:00