Skip to content
This repository was archived by the owner on Feb 17, 2023. It is now read-only.

Commit 2f6156d

Browse files
committed
use Array.forEach instead of Array.map where applicable for better performance
1 parent c9ea2df commit 2f6156d

16 files changed

Lines changed: 23 additions & 24 deletions

File tree

src/index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var util = require('util')
1111
var validate = require('har-validator')
1212

1313
// constructor
14-
var HTTPSnippet = function (data, lang) {
14+
var HTTPSnippet = function (data) {
1515
var entries
1616
var self = this
1717
var input = util._extend({}, data)
@@ -28,7 +28,7 @@ var HTTPSnippet = function (data, lang) {
2828
}]
2929
}
3030

31-
entries.map(function (entry) {
31+
entries.forEach(function (entry) {
3232
// add optional properties to make validation successful
3333
entry.request.httpVersion = entry.request.httpVersion || 'HTTP/1.1'
3434
entry.request.queryString = entry.request.queryString || []
@@ -43,8 +43,6 @@ var HTTPSnippet = function (data, lang) {
4343

4444
validate.request(entry.request, function (err, valid) {
4545
if (!valid) {
46-
debug(err)
47-
4846
throw err
4947
}
5048

@@ -110,7 +108,7 @@ HTTPSnippet.prototype.prepare = function (request) {
110108
// easter egg
111109
form._boundary = '---011000010111000001101001'
112110

113-
request.postData.params.map(function (param) {
111+
request.postData.params.forEach(function (param) {
114112
form.append(param.name, param.value || '', {
115113
filename: param.fileName || null,
116114
contentType: param.contentType || null

src/targets/c/libcurl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = function (source, options) {
1818
code.blank()
1919
.push('struct curl_slist *headers = NULL;')
2020

21-
headers.map(function (key) {
21+
headers.forEach(function (key) {
2222
code.push('headers = curl_slist_append(headers, "%s: %s");', key, source.headersObj[key])
2323
})
2424

src/targets/csharp/restsharp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = function (source, options) {
1818

1919
// construct headers
2020
if (headers.length) {
21-
headers.map(function (key) {
21+
headers.forEach(function (key) {
2222
code.push('request.AddHeader("%s", "%s");', key, source.headersObj[key])
2323
})
2424
}

src/targets/go/native.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@ module.exports = function (source, options) {
8989

9090
// Add headers
9191
if (Object.keys(source.allHeaders).length) {
92-
Object.keys(source.allHeaders).map(function (key) {
92+
Object.keys(source.allHeaders).forEach(function (key) {
9393
code.push(1, 'req.Header.Add("%s", "%s")', key, source.allHeaders[key])
9494
})
95+
9596
code.blank()
9697
}
9798

src/targets/java/okhttp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ module.exports = function (source, options) {
5959

6060
// construct headers
6161
if (headers.length) {
62-
headers.map(function (key) {
62+
headers.forEach(function (key) {
6363
code.push(1, '.addHeader("%s", "%s")', key, source.allHeaders[key])
6464
})
6565
}

src/targets/java/unirest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module.exports = function (source, options) {
3333

3434
// construct headers
3535
if (headers.length) {
36-
headers.map(function (key) {
36+
headers.forEach(function (key) {
3737
code.push(1, '.header("%s", "%s")', key, source.allHeaders[key])
3838
})
3939
}

src/targets/javascript/jquery.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = function (source, options) {
4141
case 'multipart/form-data':
4242
code.push('var form = new FormData();')
4343

44-
source.postData.params.map(function (param) {
44+
source.postData.params.forEach(function (param) {
4545
code.push('form.append(%s, %s);', JSON.stringify(param.name), JSON.stringify(param.value || param.fileName || ''))
4646
})
4747

src/targets/javascript/xhr.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = function (source, options) {
3030
case 'multipart/form-data':
3131
code.push('var data = new FormData();')
3232

33-
source.postData.params.map(function (param) {
33+
source.postData.params.forEach(function (param) {
3434
code.push('data.append(%s, %s);', JSON.stringify(param.name), JSON.stringify(param.value || param.fileName || ''))
3535
})
3636

@@ -62,7 +62,7 @@ module.exports = function (source, options) {
6262
.blank()
6363
.push('xhr.open(%s, %s);', JSON.stringify(source.method), JSON.stringify(source.fullUrl))
6464

65-
Object.keys(source.allHeaders).map(function (key) {
65+
Object.keys(source.allHeaders).forEach(function (key) {
6666
code.push('xhr.setRequestHeader(%s, %s);', JSON.stringify(key), JSON.stringify(source.allHeaders[key]))
6767
})
6868

src/targets/node/request.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ module.exports = function (source, options) {
9393

9494
var url = source.url
9595

96-
source.cookies.map(function (cookie) {
96+
source.cookies.forEach(function (cookie) {
9797
code.push('jar.setCookie(request.cookie("%s=%s"), "%s");', encodeURIComponent(cookie.name), encodeURIComponent(cookie.value), url)
9898
})
9999
code.blank()

src/targets/ocaml/cohttp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module.exports = function (source, options) {
3535
} else if (headers.length > 1) {
3636
code.push('let headers = Header.add_list (Header.init ()) [')
3737

38-
headers.map(function (key) {
38+
headers.forEach(function (key) {
3939
code.push(1, '("%s", "%s");', key, source.allHeaders[key])
4040
})
4141

0 commit comments

Comments
 (0)