Skip to content

Commit 58dce91

Browse files
committed
perf: remove argument reassignment
1 parent ede21c0 commit 58dce91

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

.eslintrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ root: true
22
rules:
33
eol-last: error
44
indent: ["error", 2, { "SwitchCase": 1 }]
5+
no-param-reassign: error
56
no-trailing-spaces: error

HISTORY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ unreleased
22
==========
33

44
* deps: depd@~1.1.2
5-
- perf: remove argument reassignment
5+
* perf: remove argument reassignment
66

77
0.7.1 / 2017-08-26
88
==================

index.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ Cookies.prototype.set = function(name, value, opts) {
102102
cookie.secure = opts.secureProxy
103103
}
104104

105-
headers = pushCookie(headers, cookie)
105+
pushCookie(headers, cookie)
106106

107107
if (opts && signed) {
108108
if (!this.keys) throw new Error('.keys required for signed cookies');
109109
cookie.value = this.keys.sign(cookie.toString())
110110
cookie.name += ".sig"
111-
headers = pushCookie(headers, cookie)
111+
pushCookie(headers, cookie)
112112
}
113113

114114
var setHeader = res.set ? http.OutgoingMessage.prototype.setHeader : res.setHeader
@@ -193,12 +193,16 @@ function getPattern(name) {
193193
)
194194
}
195195

196-
function pushCookie(cookies, cookie) {
196+
function pushCookie(headers, cookie) {
197197
if (cookie.overwrite) {
198-
cookies = cookies.filter(function(c) { return c.indexOf(cookie.name+'=') !== 0 })
198+
for (var i = headers.length - 1; i >= 0; i--) {
199+
if (headers[i].indexOf(cookie.name + '=') === 0) {
200+
headers.splice(i, 1)
201+
}
202+
}
199203
}
200-
cookies.push(cookie.toHeader())
201-
return cookies
204+
205+
headers.push(cookie.toHeader())
202206
}
203207

204208
Cookies.connect = Cookies.express = function(keys) {

0 commit comments

Comments
 (0)