Closed Bug 965783 Opened 6 years ago Closed 6 years ago

get rid of {Min,Max}Int

Categories

(Core :: XPCOM, defect)

defect
Not set

Tracking

()

RESOLVED FIXED
mozilla30

People

(Reporter: froydnj, Unassigned)

Details

Attachments

(2 files)

We should be using their std:: counterparts instead.
Converting the uses of {Min,Max}Int really deserved its own patch.  The cast in
CiteLevelTXT is to make template selection come out correctly.  The cast in
FindURLStart is to make sure that we properly do signed comparison, as |pos| is
an unsigned variable.  (Though, now that I think about it, we want to do the
subtraction in unsigned so overflow is defined, and then convert that result to
signed so the maximum is calculated correctly...)
Attachment #8367928 - Flags: review?(jduell.mcbugs)
The easy part of the patch series.
Attachment #8367929 - Flags: review?(ehsan)
Comment on attachment 8367928 [details] [diff] [review]
part 1 - convert {Min,Max}Int uses in mozTXTToHTMLConv.cpp to std::{min,max}

Review of attachment 8367928 [details] [diff] [review]:
-----------------------------------------------------------------

::: netwerk/streamconv/converters/mozTXTToHTMLConv.cpp
@@ +114,5 @@
>      int32_t remainingChars = i - aStartPos;
>      if (aInString[i] == '&')
>      {
>        subString = &aInString[i];
> +      if (!nsCRT::strncmp(subString, MOZ_UTF16("<"), std::min(4, aLength - remainingChars)))

Ugh. Can't we use nsAString::StartsWith or something?
(In reply to :Ms2ger from comment #3)
> ::: netwerk/streamconv/converters/mozTXTToHTMLConv.cpp
> @@ +114,5 @@
> >      int32_t remainingChars = i - aStartPos;
> >      if (aInString[i] == '&')
> >      {
> >        subString = &aInString[i];
> > +      if (!nsCRT::strncmp(subString, MOZ_UTF16("<"), std::min(4, aLength - remainingChars)))
> 
> Ugh. Can't we use nsAString::StartsWith or something?

All we have here are raw pointers.  I guess we could cons up an nsDependentString or something each time.  Or we could have a (syntax probably bogus):

template<size_t N>
bool
StartsWith(const char16_t* str, const char16_t needle[N], size_t amount)
{
  return !nsCRT::strncmp(str, needle, std::min(N, amount));
}

and use that instead?
Attachment #8367929 - Flags: review?(ehsan) → review+
Comment on attachment 8367928 [details] [diff] [review]
part 1 - convert {Min,Max}Int uses in mozTXTToHTMLConv.cpp to std::{min,max}

Review of attachment 8367928 [details] [diff] [review]:
-----------------------------------------------------------------

::: netwerk/streamconv/converters/mozTXTToHTMLConv.cpp
@@ +114,5 @@
>      int32_t remainingChars = i - aStartPos;
>      if (aInString[i] == '&')
>      {
>        subString = &aInString[i];
> +      if (!nsCRT::strncmp(subString, MOZ_UTF16("&lt;"), std::min(4, aLength - remainingChars)))

If you can come up with something better and it compiles :) go for it.  No need for re-review from me either way.
Attachment #8367928 - Flags: review?(jduell.mcbugs) → review+
https://hg.mozilla.org/mozilla-central/rev/c15405b8e593
https://hg.mozilla.org/mozilla-central/rev/cffc1c5928e5
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla30
You need to log in before you can comment on or make changes to this bug.