Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(736)

Issue 2810483002: Add SafeMin() and SafeMax(), which accept args of different types (Closed)

Created:
3 years, 8 months ago by kwiberg-webrtc
Modified:
3 years, 8 months ago
Reviewers:
ossu, aleloi
CC:
webrtc-reviews_webrtc.org, AleBzk, peah-webrtc, zhuangzesen_agora.io, Andrew MacDonald, aleloi, stefan-webrtc, tlegrand-webrtc, tterriberry_mozilla.com, audio-team_agora.io, hlundin-webrtc, mflodman, minyue-webrtc, the sun, aluebs-webrtc, bjornv1
Target Ref:
refs/heads/master
Project:
webrtc
Visibility:
Public.

Description

Add SafeMin() and SafeMax(), which accept args of different types Specifically, they handle all combinations of two integer and two floating-point arguments by picking a result type that is guaranteed to be able to hold the result. This means callers no longer have to deal with potentially dangerous casting to make all the arguments have the same type, like they have to with std::min() and std::max(). Also, they're constexpr. Mostly for illustrative purposes, this CL replaces a few std::min() and std::max() calls with SafeMin() and SafeMax(). BUG=webrtc:7459 Review-Url: https://codereview.webrtc.org/2810483002 Cr-Commit-Position: refs/heads/master@{#17869} Committed: https://chromium.googlesource.com/external/webrtc/+/7885d3f5c6bc6190bd4784cf41d42330ab6f9d6e

Patch Set 1 #

Patch Set 2 : Don't start using SafeClamp in this patch set #

Total comments: 9

Patch Set 3 : rebase #

Patch Set 4 : Review fixes #

Total comments: 3

Patch Set 5 : trigger error earlier #

Unified diffs Side-by-side diffs Delta from patch set Stats (+342 lines, -7 lines) Patch
M webrtc/base/BUILD.gn View 2 chunks +2 lines, -0 lines 0 comments Download
A webrtc/base/safe_minmax.h View 1 2 3 4 1 chunk +188 lines, -0 lines 0 comments Download
A webrtc/base/safe_minmax_unittest.cc View 1 2 3 1 chunk +141 lines, -0 lines 0 comments Download
M webrtc/common_video/h264/sps_vui_rewriter.cc View 2 chunks +2 lines, -2 lines 0 comments Download
M webrtc/modules/audio_coding/neteq/merge.cc View 2 chunks +4 lines, -2 lines 0 comments Download
M webrtc/modules/audio_processing/audio_processing_unittest.cc View 2 chunks +2 lines, -1 line 0 comments Download
M webrtc/modules/remote_bitrate_estimator/aimd_rate_control.cc View 1 2 3 2 chunks +3 lines, -2 lines 0 comments Download

Messages

Total messages: 44 (29 generated)
kwiberg-webrtc
3 years, 8 months ago (2017-04-09 14:46:04 UTC) #10
aleloi
I'm using this CL to learn template metaprogramming. Bear with me! https://codereview.webrtc.org/2810483002/diff/20001/webrtc/base/safe_minmax.h File webrtc/base/safe_minmax.h (right): ...
3 years, 8 months ago (2017-04-10 11:40:10 UTC) #11
ossu
This looks quite useful, but I'm concerned with the correctness when comparing an integral and ...
3 years, 8 months ago (2017-04-10 13:50:05 UTC) #12
aleloi
lowest int32_t should be -2**31=-2147483648; low is then -2147483647, which is < 1.0f. SafeMin(low, 1.0f) ...
3 years, 8 months ago (2017-04-10 14:08:12 UTC) #13
ossu
On 2017/04/10 14:08:12, aleloi wrote: > lowest int32_t should be -2**31=-2147483648; > low is then ...
3 years, 8 months ago (2017-04-10 14:25:55 UTC) #14
kwiberg-webrtc
https://codereview.webrtc.org/2810483002/diff/20001/webrtc/base/safe_minmax.h File webrtc/base/safe_minmax.h (right): https://codereview.webrtc.org/2810483002/diff/20001/webrtc/base/safe_minmax.h#newcode63 webrtc/base/safe_minmax.h:63: bool all_int = IsIntlike<T1>::value&& IsIntlike<T2>::value> On 2017/04/10 11:40:09, aleloi ...
3 years, 8 months ago (2017-04-12 18:21:21 UTC) #15
kwiberg-webrtc
On 2017/04/10 14:25:55, ossu wrote: > On 2017/04/10 14:08:12, aleloi wrote: > > lowest int32_t ...
3 years, 8 months ago (2017-04-12 18:38:54 UTC) #16
kwiberg-webrtc
I think I managed to fix everything y'all complained about, except that I only reported ...
3 years, 8 months ago (2017-04-13 00:56:05 UTC) #28
aleloi
lgtm, I like it!
3 years, 8 months ago (2017-04-13 09:31:32 UTC) #30
kwiberg-webrtc
ossu@: ping!
3 years, 8 months ago (2017-04-24 12:33:02 UTC) #31
ossu
Sorry for the delay! I was meaning to patch this one in and test locally ...
3 years, 8 months ago (2017-04-24 13:22:28 UTC) #32
kwiberg-webrtc
https://codereview.webrtc.org/2810483002/diff/100001/webrtc/base/safe_minmax_unittest.cc File webrtc/base/safe_minmax_unittest.cc (right): https://codereview.webrtc.org/2810483002/diff/100001/webrtc/base/safe_minmax_unittest.cc#newcode94 webrtc/base/safe_minmax_unittest.cc:94: // static_assert(TypeCheckMaxR<uint64_t, float, float>(), ""); On 2017/04/24 13:22:27, ossu ...
3 years, 8 months ago (2017-04-25 09:26:55 UTC) #35
ossu
On 2017/04/25 09:26:55, kwiberg-webrtc wrote: > https://codereview.webrtc.org/2810483002/diff/100001/webrtc/base/safe_minmax_unittest.cc > File webrtc/base/safe_minmax_unittest.cc (right): > > https://codereview.webrtc.org/2810483002/diff/100001/webrtc/base/safe_minmax_unittest.cc#newcode94 > ...
3 years, 8 months ago (2017-04-25 15:25:45 UTC) #38
commit-bot: I haz the power
CQ is trying da patch. Follow status at: https://chromium-cq-status.appspot.com/v2/patch-status/codereview.webrtc.org/2810483002/120001
3 years, 8 months ago (2017-04-25 19:32:15 UTC) #41
commit-bot: I haz the power
3 years, 8 months ago (2017-04-25 19:35:13 UTC) #44
Message was sent while issue was closed.
Committed patchset #5 (id:120001) as
https://chromium.googlesource.com/external/webrtc/+/7885d3f5c6bc6190bd4784cf4...

Powered by Google App Engine
This is Rietveld 408576698