Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ibu: replace ~~ with Math.trunc in res.length (option) #1288

Merged
merged 2 commits into from Dec 27, 2018
Merged

ibu: replace ~~ with Math.trunc in res.length (option) #1288

merged 2 commits into from Dec 27, 2018

Conversation

tpscrpt
Copy link
Contributor

@tpscrpt tpscrpt commented Dec 20, 2018

#1275 is fixed by this, though this implementation probably shouldn't be merged into master it can benefit whoever was suffering from the content length being too large to be notnoted.

@tpscrpt
Copy link
Contributor Author

tpscrpt commented Dec 20, 2018

test.js:

const { response } = require('./context.js')

res = response()
res.body = "Testing purposes, the average payload is most likely much larger than this; therefore some extra padding was added during the creation of this magnificent sentence."

const start = Date.now()

for(let i = 0; i < 100000000; i ++) {
  let temp = res.length
}

const diff = Date.now() - start
console.log(res.length)
console.log(diff / 1000)

@codecov
Copy link

codecov bot commented Dec 20, 2018

Codecov Report

Merging #1288 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #1288   +/-   ##
======================================
  Coverage     100%    100%           
======================================
  Files           5       5           
  Lines         393     393           
======================================
  Hits          393     393
Impacted Files Coverage Δ
lib/response.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 48993ad...f5d3640. Read the comment docs.

@@ -211,7 +211,7 @@ module.exports = {
return;
}

return ~~len;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Math.trunc(len) || 0 to avoid NaN

@dead-horse dead-horse merged commit 9be8583 into koajs:master Dec 27, 2018
kiku-jw pushed a commit to kiku-jw/koa that referenced this pull request Feb 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants