0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
Commit Graph

3727 Commits

Author SHA1 Message Date
Rich Trott
9de9a08587 path: refactor path.format() repeated code
PR-URL: https://github.com/nodejs/node/pull/5673
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
2016-03-16 10:19:41 -07:00
James M Snell
85ab4a5f12 buffer: add .from(), .alloc() and .allocUnsafe()
Several changes:

* Soft-Deprecate Buffer() constructors
* Add `Buffer.from()`, `Buffer.alloc()`, and `Buffer.allocUnsafe()`
* Add `--zero-fill-buffers` command line option
* Add byteOffset and length to `new Buffer(arrayBuffer)` constructor
* buffer.fill('') previously had no effect, now zero-fills
* Update the docs

PR-URL: https://github.com/nodejs/node/pull/4682
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
2016-03-16 08:34:02 -07:00
Rich Trott
6ba5af2c2c console: check that stderr is writable
`Console` constructor checks that `stdout.write()` is a function but
does not do an equivalent check for `stderr.write()`. If `stderr` is not
specified in the constructor, then `stderr` is set to be `stdout`.
However, if `stderr` is specified, but `stderr.write()` is not a
function, then an exception is not thrown until `console.error()` is
called.

This change adds the same check for 'stderr' in the constructor that is
there for `stdout`. If `stderr` fails the check, then a `TypeError` is
thrown.

Took the opportunity to copyedit the `console` doc a little too.

PR-URL: https://github.com/nodejs/node/pull/5635
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rod Vagg <rod@vagg.org>
2016-03-15 19:10:55 -07:00
James M Snell
b6e3fa745b events: add eventNames() method
Per https://github.com/nodejs/node/issues/1817, there are many modules
that currently abuse the private `_events` property on EventEmitter.
One of the ways it is used is to determine if a particular event is
being listened for. This adds a simple `eventNames()` method that
returns an array of the events with currently registered listeners.

PR-URL: https://github.com/nodejs/node/pull/5617
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
2016-03-15 09:25:35 -07:00
Vladimir Kurchatkin
3b2094152e net: make isIPv4 and isIPv6 more efficient
`isIPv4` and `isIPv6` are implemented on top of `isIP`, which in turn
checks the sting for being both IPv4 and IPv6, which can be inefficient
in some scenarios. This commit makes them use `uv_inet_pton` directly
instead.

PR-URL: https://github.com/nodejs/node/pull/5478
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
2016-03-15 08:32:32 -07:00
Sam Roberts
a78b3344f8 net: type check createServer options object
net.createServer('aPipe') and net.createServer(8080) are mistakes,
and now throw a TypeError instead of silently being treated as an
object.

PR-URL: https://github.com/nodejs/node/pull/2904
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2016-03-15 10:50:02 +02:00
Nathan Woltman
d0582ef9e1 lib: copy arguments object instead of leaking it
Instead of leaking the arguments object by passing it as an
argument to a function, copy it's contents to a new array,
then pass the array. This allows V8 to optimize the function
that contains this code, improving performance.

PR-URL: https://github.com/nodejs/node/pull/4361
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
2016-03-10 18:45:08 -08:00
James M Snell
8bb60e3c8d fs: improve error message for invalid flag
Flags on fs.open and others can be passed as strings or int.
Previously, if passing anything other than string or int,
the error message would only say that flags must be an int.

PR-URL: https://github.com/nodejs/node/pull/5590
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-03-09 12:27:54 -08:00
Evan Lucas
3d3b45ae95 path: fix normalize for absolutes
Fixes a regression introduced by
b212be08f6.

path.normalize(''/a/b/c/../../../x/y/z'') should return '/x/y/z'.

Fixes: https://github.com/nodejs/node/issues/5585
PR-URL: https://github.com/nodejs/node/pull/5589
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
2016-03-07 14:48:49 -06:00
Matteo Collina
8af4bb86c0 dgram: default send address to 127.0.0.1 or ::1
In net we default to 'localhost' as the default address for connect.
Not doing the same on dgram is confusing, because sending to 0.0.0.0
works on Linux/OS X but not on Windows. Defaulting that to 127.0.0.1 /
::1 addresses that.

Related: https://github.com/nodejs/node/pull/5407
Related: https://github.com/nodejs/node/issues/5398
Fixes: https://github.com/nodejs/node/issues/5487
PR-URL: https://github.com/nodejs/node/pull/5493
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
2016-03-05 19:20:31 +01:00
Alexander Makarenko
a37401e061 crypto: simplify Certificate class bindings
Replace Certificate C++ class with simple functions. Update
crypto.Certificate methods accordingly.

PR-URL: https://github.com/nodejs/node/pull/5382
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-03-05 12:29:46 +01:00
Brian White
c490b8ba54 util: improve format() performance further
Replacing the regexp and replace function with a loop improves
performance by ~60-200%.

PR-URL: https://github.com/nodejs/node/pull/5360
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-03-04 17:27:21 -06:00
Evan Lucas
8d72b0d291 util: improve util.format performance
By manually copying arguments and breaking the try/catch out, we are
able to improve the performance of util.format by 20-100% (depending on
the types).

PR-URL: https://github.com/nodejs/node/pull/5360
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-03-04 17:27:15 -06:00
Ali Ijaz Sheikh
953173b0d7 lib: wrap tick_processor scripts in IIFE
PR-URL: https://github.com/nodejs/node/pull/4722
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
2016-03-03 20:35:20 -08:00
Fedor Indutny
b010c87164 crypto, string_bytes: treat buffer str as utf8
Do not treat crypto inputs as `binary` strings, convert them to Buffers
using `new Buffer(..., 'utf8')`, or using newly updated StringBytes
APIs.

PR-URL: https://github.com/nodejs/node/pull/5522
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-03-02 21:25:04 +03:00
Anton Khlynovskiy
c647e87504 lib: freelist: use .pop() for allocation
Array#pop() is known to be faster than Array#shift().
To be exact, it's O(1) vs. O(n). In this case there's no difference
from which side of the "pool" array the object is retrieved,
so .pop() should be preferred.

PR-URL: https://github.com/nodejs/node/pull/2174
Reviewed-By: mscdex - Brian White <mscdex@mscdex.net>
Reviewed-By: jasnell - James M Snell <jasnell@gmail.com>
Reviewed-By: ofrobots - Ali Ijaz Sheikh <ofrobots@google.com>
2016-03-02 09:24:24 -08:00
nettofarah
610bd8d567 url: group slashed protocols by protocol name
Reorder slashed protocols so they are grouped by protocol name. This is
done so it doesn't look like we're duplicating protocol names at the
bottom of the list.

PR-URL: https://github.com/nodejs/node/pull/5380
Reviewed-By: Evan Lucas <evanlucas@me.com>
2016-02-29 20:26:59 -06:00
Owen Smith
f296a7f16f path: fix path.relative() for prefixes at root
Fixes #5485

PR-URL: https://github.com/nodejs/node/pull/5490
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Brian White <mscdex@mscdex.net>
2016-02-29 20:10:04 +01:00
Zheng Chaoping
4717ea9186 path: fix win32 parse()
Fix path.win32.parse("/foo/bar") retuns `{root: '' ...}`(v5.7.0),
but not `{root: '/' ...}`(v5.6.0).

PR-URL: https://github.com/nodejs/node/pull/5484
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Roman Reiss <me@silverwind.io>
2016-02-29 19:39:56 +01:00
Prince J Wesley
40d57b714e repl: fix stack trace column number in strict mode
On strict mode, "'use strict'; void 0; " is added as prefix
in order to prevent "use strict" as the result value
for let/const statements. It causes wrong column number in
stack trace.

PR-URL: https://github.com/nodejs/node/pull/5416
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
2016-02-29 10:46:31 +01:00
Matteo Collina
725ffdb9b7 dgram: handle default address case when offset and length are specified
Fixes a regression introduced by: https://github.com/nodejs/node/pull/4374.
Adds a new test to avoid similar issue in the future.
The test is disabled on windows, because this feature never worked
there.

Fixes: https://github.com/nodejs/node/issues/5398
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Evan Lucas <evanlucas@me.com>
2016-02-28 11:25:36 +01:00
Owen Smith
e326950498 path: fix win32 relative() for UNC paths
win32 normalize() will output a trailing '\' for some UNC paths. trim
them before processing

Change by @mscdex

Add basic UNC path tests to win32 relative()

PR-URL: https://github.com/nodejs/node/pull/5456
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Roman Reiss <me@silverwind.io>
2016-02-27 17:30:44 +01:00
Owen Smith
b33879d9e2 path: fix win32 relative() when "to" is a prefix
when the basename of "to" was a prefix of the basename of "from" win32
relative() would miss including it in the result

Fixes: https://github.com/nodejs/node/issues/5447
PR-URL: https://github.com/nodejs/node/pull/5456
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Roman Reiss <me@silverwind.io>
2016-02-27 17:29:29 +01:00
Brian White
8b16ba3bbf url: fix off-by-one error with parse()
Fixes: https://github.com/nodejs/node/issues/5393
PR-URL: https://github.com/nodejs/node/pull/5394
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Evan Lucas <evanlucas@me.com>
2016-02-27 14:45:20 +01:00
Brian White
3a331b66f8 path: fix verbose relative() output
Fixes: https://github.com/nodejs/node/issues/5383
PR-URL: https://github.com/nodejs/node/pull/5389
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Evan Lucas <evanlucas@me.com>
2016-02-27 14:42:33 +01:00
Jeremiah Senkpiel
67963c8c66 timers: greatly improve code comments
Describes the How and Why of the timers implementation, as well as
adding comments in spots that should allow for an easier understanding
about what is going on.

The timers implementation is very efficient, at a cost.
That cost is readable understandability, and this aims to improve that.

PR-URL: https://github.com/nodejs/node/pull/4007
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Julien Gilli <jgilli@nodejs.org>
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
2016-02-26 18:07:36 -05:00
Jeremiah Senkpiel
60f8c1acf4 timers: refactor timers
Consolidates the implementation of regular and internal (_unrefActive)
timers.

Also includes a couple optimizations:
- Isolates the try/catch from listOnTimeout() in a new tryOnTimeout().
- Uses a TimersList constructor as the base for linkedlists.

Additionally includes other cleanup and clarification, such as a rename
of "Timer" to "TimerWrap".

PR-URL: https://github.com/nodejs/node/pull/4007
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Julien Gilli <jgilli@nodejs.org>
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
2016-02-26 18:07:36 -05:00
Stefan Budeanu
7c48cb5601 crypto: Improve control of FIPS mode
Default to FIPS off even in FIPS builds.
Add JS API to check and control FIPS mode.
Add command line arguments to force FIPS on/off.
Respect OPENSSL_CONF variable and read the config.
Add testing for new features.

Fixes: https://github.com/nodejs/node/issues/3819
PR-URL: https://github.com/nodejs/node/pull/5181
Reviewed-By: Fedor Indutny <fedor@indutny.com>
Reviewed-by: Michael Dawson <michael_dawson@ca.ibm.com>
2016-02-25 15:06:41 -05:00
cjihrig
ee7754be47 repl: accept no arguments to start()
Currently, there is a check to ensure that the user either
provides an object or a string to repl.start(). The string case
is used to set a REPL prompt. However, a default of '> ' already
exists, so forcing the user to specify a prompt is a bit
redundant. This commit removes this restriction.

Fixes: https://github.com/nodejs/node/issues/5385
PR-URL: https://github.com/nodejs/node/pull/5388
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Julian Duque <julianduquej@gmail.com>
2016-02-25 08:48:43 -05:00
Ben Noordhuis
66f4586dd0 cluster: emit worker as first 'message' event arg
It's documented as such but didn't actually behave that way.

Bug introduced in commit 66fc8ca ("cluster: emit 'message' event on
cluster master"), which is the commit that introduced the event.

Fixes: https://github.com/nodejs/node/issues/5126
PR-URL: https://github.com/nodejs/node/pull/5361
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
2016-02-25 12:46:37 +01:00
Rich Trott
d26417f123 tools: apply custom buffer lint rule to /lib only
The lint rule is there to avoid a circular-dependency issue that only
applies to `/lib`. In preparation for linting `/benchmark`, apply that
rule to `/lib` only to avoid churn in `/benchmark`.

Refs: https://github.com/nodejs/node/issues/3983#issuecomment-158956113
PR-URL: https://github.com/nodejs/node/pull/5371
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
2016-02-24 20:09:52 -08:00
cjihrig
e854f60585 child_process: add keepOpen option to send()
This option allows an instance of net.Socket to be kept open in
the sending process.

Fixes: https://github.com/nodejs/node/issues/4271
PR-URL: https://github.com/nodejs/node/pull/5283
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-02-22 11:55:30 -05:00
cjihrig
1952844f45 child_process: support options in send()
This commit adds an options object to process.send(). The same
object is propagated to process._send(), the _handleQueue, and the
send() and postSend() functions of the handle converter.

Fixes: https://github.com/nodejs/node/issues/4271
PR-URL: https://github.com/nodejs/node/pull/5283
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-02-22 11:53:38 -05:00
Rich Trott
c9d7b75346 debugger: remove unneeded callback check
In `lib/_debugger.js`, remove check for `cb` in line 571 as it is
guaranteed to be truthy due to line 521.

PR-URL: https://github.com/nodejs/node/pull/5319
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-02-19 14:54:08 -08:00
Brian White
7d1d3a6621 url: fix lint and deopt issues
The deopt issues arose from the use of const in specific situations
that v8 does not fully support yet.

Fixes: https://github.com/nodejs/node/issues/5299
PR-URL: https://github.com/nodejs/node/pull/5300
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2016-02-18 09:55:03 -08:00
Brian White
db9128135f url: improve url.parse() performance
This commit improves url.parse() performance by 50-210%
with the existing url/url-parse benchmarks. Also, the
optimizations made in url.format() result in a 40%
increase in performance for url.resolve().

Some optimization strategies used in this commit include:
* Combining multiple searches on the same string into a
   single loop
* Avoiding unnecessary string.split() and array.join()
* Minimizing creation of temporary strings
* Using a faster alternative to encodeURIComponent,
   borrowed from the querystring module

PR-URL: https://github.com/nodejs/node/pull/4892
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ryan Graham <r.m.graham@gmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
2016-02-18 07:58:21 -05:00
Jackson Tian
0903b6d8a8 console: apply null as this for util.format
Util.format is just a stateless function. Apply current console
as `this` is unnecessary.

PR-URL: https://github.com/nodejs/node/pull/5222
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
2016-02-18 11:24:01 +01:00
Brian White
9209bf6d43 path: fix input type checking regression
Before b212be08f6, input types were not checked in some path functions
and the inputs were passed directly to `regexp.exec()` which
implicitly converts its argument to a string.

This commit both removes the type checking added in b212be08f6 and
adds string coercion for those functions.

PR-URL: https://github.com/nodejs/node/pull/5244
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
2016-02-17 14:18:43 -05:00
Brian White
92212014ff stream: fix no data on partial decode
Before this commit, it was possible to push a partial character
to a readable stream where it was decoded as an empty string and
then added to the internal buffer. This caused the stream to not
emit any data, even when the rest of the character bytes were pushed
separately, because of a non-zero length check of the first chunk in
the internal buffer.

Fixes: https://github.com/nodejs/node/issues/5223
PR-URL: https://github.com/nodejs/node/pull/5226
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-02-17 14:15:47 -05:00
Fedor Indutny
7885b1d7aa net: use _server for internal book-keeping
The role of `this.server` is now split between `this._server` and
`this.server`. Where the first one is used for counting active
connections of `net.Server`, and the latter one is just a public API for
users' consumption.

The reasoning for this is simple, `TLSSocket` instances wrap
`net.Socket` instances, thus both refer to the `net.Server` through the
`this.server` property. However, only one of them should be used for
`net.Server` connection count book-keeping, otherwise double-decrement
will happen on socket destruction.

Fix: #5083
PR-URL: https://github.com/nodejs/node/pull/5262
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-02-17 13:58:24 -05:00
Alexander Makarenko
836c659d8f http,util: fix typos in comments
Fix several typos in comments.

PR-URL: https://github.com/nodejs/node/pull/5279
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-02-17 08:43:40 -08:00
Fedor Indutny
aa0526972a tls: nullify .ssl on handle close
This is an intermediate fix for an issue of accessing `TLSWrap` fields
after the parent handle was destroyed. While `close` listener cleans up
this field automatically, it can be done even earlier at the
`TLSWrap.close` call.

Proper fix is going to be submitted and landed after this one.

Fix: #5108
PR-URL: https://github.com/nodejs/node/pull/5168
Reviewed-By: Shigeki Ohtsu <ohtsu@iij.ad.jp>
2016-02-16 14:12:45 -05:00
Zirak
a06066ca31 repl: allow multiline function call
Currently, the repl allows multiline function declarations, strings, and
all sorts of niceties by catching the SyntaxErrors they issue and
ignoring them. However, the SyntaxError raised by multiline function
calls was not caught. This commit adds to the whitelist.

PR-URL: https://github.com/nodejs/node/pull/3823
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
2016-02-16 14:03:54 +05:30
Igor Klopov
e9ac83ab35 cluster: dont rely on this in fork
PR-URL: https://github.com/nodejs/node/pull/5216
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rod Vagg <rod@vagg.org>
2016-02-16 14:58:52 +11:00
Brian White
fab240a886 http: remove old, confusing comment
The comment refers to a property (called `_pendings`) that no longer
exists.

PR-URL: https://github.com/nodejs/node/pull/5233
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-02-15 07:52:21 -08:00
Brian White
0223de6ba5 http: remove unnecessary check
The value passed to `process.nextTick()` which is passed to the
callback is already a valid object, so the conditional will always
evaluate to true.

PR-URL: https://github.com/nodejs/node/pull/5233
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-02-15 07:52:17 -08:00
Сковорода Никита Андреевич
1d79787e2e fs: add a temporary fix for re-evaluation support
This is needed to give users a grace period before actually breaking
modules that re-evaluate fs sources from context where internal modules
are not allowed, e.g. older version of graceful-fs module.

To be reverted in Node.js 7.0

Fixes: #5097, see also #1898, #2026, and #4525.
PR-URL: https://github.com/nodejs/node/pull/5102
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-02-12 20:37:37 -08:00
Brian White
00638ac160 querystring: improve escape() performance
This commit improves escape() performance by up to 15% with the
existing querystring-stringify benchmarks by reducing the number
of string concatentations. A potential deopt is also avoided by
making sure the index passed to charCodeAt() is within bounds.

PR-URL: https://github.com/nodejs/node/pull/5012
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2016-02-12 20:00:22 -05:00
Brian White
c8e650dee7 querystring: improve unescapeBuffer() performance
Before this, v8 would deopt when an out of bounds `inIndex` would get
passed to charCodeAt(). charCodeAt() returns NaN in such cases, so we
directly emulate that behavior as well.

Also, calls to charCodeAt() for constant strings have been replaced
by the raw character codes and parser state is now stored as an
integer instead of a string. Both of these provide a slight
performance increase.

PR-URL: https://github.com/nodejs/node/pull/5012
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2016-02-12 20:00:13 -05:00
Brian White
a2a69a2b63 querystring: improve parse() performance
This commit improves parse() performance by ~20-200% with the various
querystring-parse benchmarks.

Some optimization strategies used in this commit include:
* Combining multiple searches (for '&', '=', and '+') on the same
   string into a single loop
* Avoiding string.split()
* Minimizing creation of temporary strings
* Avoiding string decoding if no encoded bytes were found and the
   default string decoder is being used

PR-URL: https://github.com/nodejs/node/pull/5012
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2016-02-12 19:59:49 -05:00