Skip to content

Commit

Permalink
ICU-22793 Remove superfluous return value typecasts to UBool.
Browse files Browse the repository at this point in the history
  • Loading branch information
roubert committed Sep 19, 2024
1 parent 07e0f7e commit 0bf8a95
Show file tree
Hide file tree
Showing 54 changed files with 133 additions and 138 deletions.
4 changes: 2 additions & 2 deletions icu4c/source/common/bmpset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,14 @@ BMPSet::contains(UChar32 c) const {
if (static_cast<uint32_t>(c) <= 0xff) {
return latin1Contains[c];
} else if (static_cast<uint32_t>(c) <= 0x7ff) {
return static_cast<UBool>((table7FF[c & 0x3f] & (static_cast<uint32_t>(1) << (c >> 6))) != 0);
return (table7FF[c & 0x3f] & (static_cast<uint32_t>(1) << (c >> 6))) != 0;
} else if (static_cast<uint32_t>(c) < 0xd800 || (c >= 0xe000 && c <= 0xffff)) {
int lead=c>>12;
uint32_t twoBits=(bmpBlockBits[(c>>6)&0x3f]>>lead)&0x10001;
if(twoBits<=1) {
// All 64 code points with the same bits 15..6
// are either in the set or not.
return static_cast<UBool>(twoBits);
return twoBits;
} else {
// Look up the code point in its 4k block of code points.
return containsSlow(c, list4kStarts[lead], list4kStarts[lead+1]);
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/common/bmpset.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class BMPSet : public UMemory {
};

inline UBool BMPSet::containsSlow(UChar32 c, int32_t lo, int32_t hi) const {
return static_cast<UBool>(findCodePoint(c, lo, hi) & 1);
return findCodePoint(c, lo, hi) & 1;
}

U_NAMESPACE_END
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/common/normalizer2impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ class U_COMMON_API Normalizer2Impl : public UObject {
// 0<=lead<=0xffff
uint8_t bits=smallFCD[lead>>8];
if(bits==0) { return false; }
return static_cast<UBool>((bits >> ((lead >> 5) & 7)) & 1);
return (bits >> ((lead >> 5) & 7)) & 1;
}
/** Returns the FCD value from the regular normalization data. */
uint16_t getFCD16FromNormData(UChar32 c) const;
Expand Down
10 changes: 5 additions & 5 deletions icu4c/source/common/patternprops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ PatternProps::isSyntax(UChar32 c) {
if(c<0) {
return false;
} else if(c<=0xff) {
return static_cast<UBool>(latin1[c] >> 1) & 1;
return (latin1[c] >> 1) & 1;
} else if(c<0x2010) {
return false;
} else if(c<=0x3030) {
uint32_t bits=syntax2000[index2000[(c-0x2000)>>5]];
return static_cast<UBool>((bits >> (c & 0x1f)) & 1);
return (bits >> (c & 0x1f)) & 1;
} else if(0xfd3e<=c && c<=0xfe46) {
return c<=0xfd3f || 0xfe45<=c;
} else {
Expand All @@ -138,12 +138,12 @@ PatternProps::isSyntaxOrWhiteSpace(UChar32 c) {
if(c<0) {
return false;
} else if(c<=0xff) {
return static_cast<UBool>(latin1[c] & 1);
return latin1[c] & 1;
} else if(c<0x200e) {
return false;
} else if(c<=0x3030) {
uint32_t bits=syntaxOrWhiteSpace2000[index2000[(c-0x2000)>>5]];
return static_cast<UBool>((bits >> (c & 0x1f)) & 1);
return (bits >> (c & 0x1f)) & 1;
} else if(0xfd3e<=c && c<=0xfe46) {
return c<=0xfd3f || 0xfe45<=c;
} else {
Expand All @@ -156,7 +156,7 @@ PatternProps::isWhiteSpace(UChar32 c) {
if(c<0) {
return false;
} else if(c<=0xff) {
return static_cast<UBool>(latin1[c] >> 2) & 1;
return (latin1[c] >> 2) & 1;
} else if(0x200e<=c && c<=0x2029) {
return c<=0x200f || 0x2028<=c;
} else {
Expand Down
12 changes: 6 additions & 6 deletions icu4c/source/common/putil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ uprv_isNaN(double number)
BitPatternConversion convertedNumber;
convertedNumber.d64 = number;
/* Infinity is 0x7FF0000000000000U. Anything greater than that is a NaN */
return (UBool)((convertedNumber.i64 & U_INT64_MAX) > gInf.i64);
return (convertedNumber.i64 & U_INT64_MAX) > gInf.i64;

#elif U_PLATFORM == U_PF_OS390
uint32_t highBits = *(uint32_t*)u_topNBytesOfDouble(&number,
Expand All @@ -368,7 +368,7 @@ uprv_isInfinite(double number)
BitPatternConversion convertedNumber;
convertedNumber.d64 = number;
/* Infinity is exactly 0x7FF0000000000000U. */
return (UBool)((convertedNumber.i64 & U_INT64_MAX) == gInf.i64);
return (convertedNumber.i64 & U_INT64_MAX) == gInf.i64;
#elif U_PLATFORM == U_PF_OS390
uint32_t highBits = *(uint32_t*)u_topNBytesOfDouble(&number,
sizeof(uint32_t));
Expand All @@ -389,7 +389,7 @@ U_CAPI UBool U_EXPORT2
uprv_isPositiveInfinity(double number)
{
#if IEEE_754 || U_PLATFORM == U_PF_OS390
return (UBool)(number > 0 && uprv_isInfinite(number));
return number > 0 && uprv_isInfinite(number);
#else
return uprv_isInfinite(number);
#endif
Expand All @@ -399,7 +399,7 @@ U_CAPI UBool U_EXPORT2
uprv_isNegativeInfinity(double number)
{
#if IEEE_754 || U_PLATFORM == U_PF_OS390
return (UBool)(number < 0 && uprv_isInfinite(number));
return number < 0 && uprv_isInfinite(number);

#else
uint32_t highBits = *(uint32_t*)u_topNBytesOfDouble(&number,
Expand Down Expand Up @@ -744,11 +744,11 @@ static UBool isValidOlsonID(const char *id) {
The timezone is sometimes set to "CST-7CDT", "CST6CDT5,J129,J131/19:30",
"GRNLNDST3GRNLNDDT" or similar, so we cannot use it.
The rest of the time it could be an Olson ID. George */
return static_cast<UBool>(id[idx] == 0
return id[idx] == 0
|| uprv_strcmp(id, "PST8PDT") == 0
|| uprv_strcmp(id, "MST7MDT") == 0
|| uprv_strcmp(id, "CST6CDT") == 0
|| uprv_strcmp(id, "EST5EDT") == 0);
|| uprv_strcmp(id, "EST5EDT") == 0;
}

/* On some Unix-like OS, 'posix' subdirectory in
Expand Down
6 changes: 3 additions & 3 deletions icu4c/source/common/ubidi_props.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ ubidi_getClass(UChar32 c) {
U_CFUNC UBool
ubidi_isMirrored(UChar32 c) {
uint16_t props=UTRIE2_GET16(&ubidi_props_singleton.trie, c);
return (UBool)UBIDI_GET_FLAG(props, UBIDI_IS_MIRRORED_SHIFT);
return UBIDI_GET_FLAG(props, UBIDI_IS_MIRRORED_SHIFT);
}

static UChar32
Expand Down Expand Up @@ -183,13 +183,13 @@ ubidi_getMirror(UChar32 c) {
U_CFUNC UBool
ubidi_isBidiControl(UChar32 c) {
uint16_t props=UTRIE2_GET16(&ubidi_props_singleton.trie, c);
return (UBool)UBIDI_GET_FLAG(props, UBIDI_BIDI_CONTROL_SHIFT);
return UBIDI_GET_FLAG(props, UBIDI_BIDI_CONTROL_SHIFT);
}

U_CFUNC UBool
ubidi_isJoinControl(UChar32 c) {
uint16_t props=UTRIE2_GET16(&ubidi_props_singleton.trie, c);
return (UBool)UBIDI_GET_FLAG(props, UBIDI_JOIN_CONTROL_SHIFT);
return UBIDI_GET_FLAG(props, UBIDI_JOIN_CONTROL_SHIFT);
}

U_CFUNC UJoiningType
Expand Down
10 changes: 5 additions & 5 deletions icu4c/source/common/ucase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,17 +696,17 @@ getDotType(UChar32 c) {

U_CAPI UBool U_EXPORT2
ucase_isSoftDotted(UChar32 c) {
return (UBool)(getDotType(c)==UCASE_SOFT_DOTTED);
return getDotType(c)==UCASE_SOFT_DOTTED;
}

U_CAPI UBool U_EXPORT2
ucase_isCaseSensitive(UChar32 c) {
uint16_t props=UTRIE2_GET16(&ucase_props_singleton.trie, c);
if(!UCASE_HAS_EXCEPTION(props)) {
return (UBool)((props&UCASE_SENSITIVE)!=0);
return (props&UCASE_SENSITIVE)!=0;
} else {
const uint16_t *pe=GET_EXCEPTIONS(&ucase_props_singleton, props);
return (UBool)((*pe&UCASE_EXC_SENSITIVE)!=0);
return (*pe&UCASE_EXC_SENSITIVE)!=0;
}
}

Expand Down Expand Up @@ -1623,12 +1623,12 @@ ucase_toFullFolding(UChar32 c,

U_CAPI UBool U_EXPORT2
u_isULowercase(UChar32 c) {
return (UBool)(UCASE_LOWER==ucase_getType(c));
return UCASE_LOWER==ucase_getType(c);
}

U_CAPI UBool U_EXPORT2
u_isUUppercase(UChar32 c) {
return (UBool)(UCASE_UPPER==ucase_getType(c));
return UCASE_UPPER==ucase_getType(c);
}

/* Transforms the Unicode character to its lower case equivalent.*/
Expand Down
Loading

0 comments on commit 0bf8a95

Please sign in to comment.