mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
stream: improve Writable.destroy performance
Avoid nextTick if there are no pending callbacks. PR-URL: https://github.com/nodejs/node/pull/35067 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ricky Zhou <0x19951125@gmail.com>
This commit is contained in:
@@ -45,6 +45,7 @@ const {
|
||||
getHighWaterMark,
|
||||
getDefaultHighWaterMark
|
||||
} = require('internal/streams/state');
|
||||
const assert = require('internal/assert');
|
||||
const {
|
||||
ERR_INVALID_ARG_TYPE,
|
||||
ERR_METHOD_NOT_IMPLEMENTED,
|
||||
@@ -826,9 +827,16 @@ ObjectDefineProperties(Writable.prototype, {
|
||||
const destroy = destroyImpl.destroy;
|
||||
Writable.prototype.destroy = function(err, cb) {
|
||||
const state = this._writableState;
|
||||
if (!state.destroyed) {
|
||||
|
||||
// Invoke pending callbacks.
|
||||
if (
|
||||
state.bufferedIndex < state.buffered.length ||
|
||||
state[kOnFinished].length
|
||||
) {
|
||||
assert(!state.destroyed);
|
||||
process.nextTick(errorBuffer, state);
|
||||
}
|
||||
|
||||
destroy.call(this, err, cb);
|
||||
return this;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user