Let RTC_[D]CHECK_op accept arguments of different signedness
With this change, instead of
RTC_DCHECK_GE(unsigned_var, 17u);
we can simply write
RTC_DCHECK_GE(unsigned_var, 17);
or even
RTC_DCHECK_GE(unsigned_var, -17); // Always true.
and the mathematically sensible thing will happen.
Perhaps more importantly, we can replace checks like
// index is size_t, num_channels is int.
RTC_DCHECK(num_channels >= 0
&& index < static_cast<size_t>(num_channels));
or, even worse, just
// Surely num_channels isn't negative. That would be absurd!
RTC_DCHECK_LT(index, static_cast<size_t>(num_channels));
with simply
RTC_DCHECK_LT(index, num_channels);
In short, you no longer have to keep track of the signedness of the arguments, because the sensible thing will happen.
BUG=webrtc:6645
Review-Url: https://codereview.webrtc.org/2459793002
Cr-Commit-Position: refs/heads/master@{#14878}
2016-11-01 12:04:26 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright 2016 The WebRTC Project Authors. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-04-10 22:44:07 -07:00
|
|
|
// This file defines six constexpr functions:
|
Let RTC_[D]CHECK_op accept arguments of different signedness
With this change, instead of
RTC_DCHECK_GE(unsigned_var, 17u);
we can simply write
RTC_DCHECK_GE(unsigned_var, 17);
or even
RTC_DCHECK_GE(unsigned_var, -17); // Always true.
and the mathematically sensible thing will happen.
Perhaps more importantly, we can replace checks like
// index is size_t, num_channels is int.
RTC_DCHECK(num_channels >= 0
&& index < static_cast<size_t>(num_channels));
or, even worse, just
// Surely num_channels isn't negative. That would be absurd!
RTC_DCHECK_LT(index, static_cast<size_t>(num_channels));
with simply
RTC_DCHECK_LT(index, num_channels);
In short, you no longer have to keep track of the signedness of the arguments, because the sensible thing will happen.
BUG=webrtc:6645
Review-Url: https://codereview.webrtc.org/2459793002
Cr-Commit-Position: refs/heads/master@{#14878}
2016-11-01 12:04:26 -07:00
|
|
|
//
|
Rename safe_cmp::{Eq,Ne,Lt,Le,Ge,Gt} to Safe{Eq,Ne,Lt,Le,Ge,Gt}
For consistency with SafeMin(), SafeMax(), and SafeClamp(). And so that we avoid introducing a namespace.
BUG=webrtc:7459
Review-Url: https://codereview.webrtc.org/2802423002
Cr-Commit-Position: refs/heads/master@{#18756}
2017-06-26 01:31:31 -07:00
|
|
|
// rtc::SafeEq // ==
|
|
|
|
|
// rtc::SafeNe // !=
|
|
|
|
|
// rtc::SafeLt // <
|
|
|
|
|
// rtc::SafeLe // <=
|
|
|
|
|
// rtc::SafeGt // >
|
|
|
|
|
// rtc::SafeGe // >=
|
Let RTC_[D]CHECK_op accept arguments of different signedness
With this change, instead of
RTC_DCHECK_GE(unsigned_var, 17u);
we can simply write
RTC_DCHECK_GE(unsigned_var, 17);
or even
RTC_DCHECK_GE(unsigned_var, -17); // Always true.
and the mathematically sensible thing will happen.
Perhaps more importantly, we can replace checks like
// index is size_t, num_channels is int.
RTC_DCHECK(num_channels >= 0
&& index < static_cast<size_t>(num_channels));
or, even worse, just
// Surely num_channels isn't negative. That would be absurd!
RTC_DCHECK_LT(index, static_cast<size_t>(num_channels));
with simply
RTC_DCHECK_LT(index, num_channels);
In short, you no longer have to keep track of the signedness of the arguments, because the sensible thing will happen.
BUG=webrtc:6645
Review-Url: https://codereview.webrtc.org/2459793002
Cr-Commit-Position: refs/heads/master@{#14878}
2016-11-01 12:04:26 -07:00
|
|
|
//
|
|
|
|
|
// They each accept two arguments of arbitrary types, and in almost all cases,
|
|
|
|
|
// they simply call the appropriate comparison operator. However, if both
|
|
|
|
|
// arguments are integers, they don't compare them using C++'s quirky rules,
|
|
|
|
|
// but instead adhere to the true mathematical definitions. It is as if the
|
|
|
|
|
// arguments were first converted to infinite-range signed integers, and then
|
|
|
|
|
// compared, although of course nothing expensive like that actually takes
|
|
|
|
|
// place. In practice, for signed/signed and unsigned/unsigned comparisons and
|
|
|
|
|
// some mixed-signed comparisons with a compile-time constant, the overhead is
|
|
|
|
|
// zero; in the remaining cases, it is just a few machine instructions (no
|
|
|
|
|
// branches).
|
|
|
|
|
|
|
|
|
|
#ifndef WEBRTC_BASE_SAFE_COMPARE_H_
|
|
|
|
|
#define WEBRTC_BASE_SAFE_COMPARE_H_
|
|
|
|
|
|
|
|
|
|
|
2017-06-28 20:58:07 +02:00
|
|
|
// This header is deprecated and is just left here temporarily during
|
|
|
|
|
// refactoring. See https://bugs.webrtc.org/7634 for more details.
|
|
|
|
|
#include "webrtc/rtc_base/safe_compare.h"
|
Let RTC_[D]CHECK_op accept arguments of different signedness
With this change, instead of
RTC_DCHECK_GE(unsigned_var, 17u);
we can simply write
RTC_DCHECK_GE(unsigned_var, 17);
or even
RTC_DCHECK_GE(unsigned_var, -17); // Always true.
and the mathematically sensible thing will happen.
Perhaps more importantly, we can replace checks like
// index is size_t, num_channels is int.
RTC_DCHECK(num_channels >= 0
&& index < static_cast<size_t>(num_channels));
or, even worse, just
// Surely num_channels isn't negative. That would be absurd!
RTC_DCHECK_LT(index, static_cast<size_t>(num_channels));
with simply
RTC_DCHECK_LT(index, num_channels);
In short, you no longer have to keep track of the signedness of the arguments, because the sensible thing will happen.
BUG=webrtc:6645
Review-Url: https://codereview.webrtc.org/2459793002
Cr-Commit-Position: refs/heads/master@{#14878}
2016-11-01 12:04:26 -07:00
|
|
|
|
|
|
|
|
#endif // WEBRTC_BASE_SAFE_COMPARE_H_
|