The default bug view has changed. See this FAQ.

recent warning abatement

RESOLVED FIXED in mozilla17

Status

()

Core
JavaScript Engine
RESOLVED FIXED
5 years ago
5 years ago

People

(Reporter: brendan, Assigned: brendan)

Tracking

Trunk
mozilla17
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment, 1 obsolete attachment)

(Assignee)

Description

5 years ago
Created attachment 647068 [details] [diff] [review]
fix warnings on Mac shell builds, use canonical names

Attached patch fixes these recent additions:

3,6d2
< Darwin_DBG.OBJ/made:/Users/brendaneich/Hacking/hg.mozilla.org/mozilla-central/js/src/gc/Marking.cpp:119: warning: NULL used in arithmetic
< Darwin_DBG.OBJ/made:/Users/brendaneich/Hacking/hg.mozilla.org/mozilla-central/js/src/gc/Marking.cpp:370: warning: NULL used in arithmetic
< Darwin_DBG.OBJ/made:/Users/brendaneich/Hacking/hg.mozilla.org/mozilla-central/js/src/jsscript.cpp:1234: warning: unused variable ‘memlen’
< Darwin_DBG.OBJ/made:/Users/brendaneich/Hacking/hg.mozilla.org/mozilla-central/js/src/jsscript.cpp:1235: warning: unused variable ‘COMPRESS_THRESHOLD’
10,11d5
< Darwin_OPT.OBJ/made:/Users/brendaneich/Hacking/hg.mozilla.org/mozilla-central/js/src/jsscript.cpp:1234: warning: unused variable ‘memlen’
< Darwin_OPT.OBJ/made:/Users/brendaneich/Hacking/hg.mozilla.org/mozilla-central/js/src/jsscript.cpp:1235: warning: unused variable ‘COMPRESS_THRESHOLD’

I noticed overloading of len/Len/Length as a name part. It's plausible for linear measures but the canonical name for concrete size_t byte lengths in SpiderMonkey is nbytes, also "size", in contrast to more abstract number-of-vector-elements "length" or ...Length.

In this light compressedLength still works, and it's more readable. The reader just has to know that ScriptSource::length_ counts jschar elements while ScriptSource::compressedLength (no trailing _ there, not sure why not) counts bytes.

Canonical naming helps grepability as well as style coherence. I hope it continues.

/be
Attachment #647068 - Flags: review?(dmandelin)
(Assignee)

Comment 1

5 years ago
Comment on attachment 647068 [details] [diff] [review]
fix warnings on Mac shell builds, use canonical names

>@@ -1357,22 +1357,23 @@ ScriptSource::performXDR(XDRState<mode> 
>             xdr->cx()->runtime->gcIsFull)
>             ss->marked = true;
> #endif
>     }
>     if (!xdr->codeUint32(&ss->length_))
>         return false;
>     if (!xdr->codeUint32(&ss->compressedLength))
>         return false;
>+
>     uint8_t argumentsNotIncluded = ss->argumentsNotIncluded_;
>     if (!xdr->codeUint8(&argumentsNotIncluded))
>         return false;
>     ss->argumentsNotIncluded_ = argumentsNotIncluded;
>-    size_t byteLen = ss->compressed() ? ss->compressedLength :
>-        (ss->length_ * sizeof(jschar));
>+
>+    size_t byteLen = ss->compressed() ? ss->compressedLength : (ss->length_ * sizeof(jschar));
>     if (mode == XDR_DECODE) {
>         ss->data.compressed = static_cast<unsigned char *>(xdr->cx()->malloc_(byteLen));
>         if (!ss->data.compressed)
>             return false;
>     }
>     if (!xdr->codeBytes(ss->data.compressed, byteLen))
>         return false;
>     if (mode == XDR_DECODE) {

Another style fix: newlines before code paragraphs (especially those starting with initialized declarations) if not preceded by {. See http://steveholt.org/2012/7/19/what-makes-code-readable.

/be

Comment 2

5 years ago
Comment on attachment 647068 [details] [diff] [review]
fix warnings on Mac shell builds, use canonical names

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

::: js/src/jsscript.cpp
@@ +1234,5 @@
>  
>  #if USE_ZLIB
> +    const size_t nbytes = length_ * sizeof(jschar);
> +    const size_t COMPRESS_THRESHOLD = 512;
> +    size_t compressed_nbytes;

I don't understand this name. ncompressedBytes would seem to reflect the camelCase convention of the rest of the variables.
(Assignee)

Comment 3

5 years ago
In general, locals use camelCase but not exclusively. The old nbytes-style names from K&R and similar don't mix well with Smalltalk-y camelCase.

But this reminds me to ask again about

"ScriptSource::compressedLength (no trailing _ there, not sure why not)"

If the member had a trailing _, the local could use the same name without trailing _. That seems even better.

/be
(Assignee)

Comment 4

5 years ago
Created attachment 647193 [details] [diff] [review]
like so
Attachment #647068 - Attachment is obsolete: true
Attachment #647068 - Flags: review?(dmandelin)
Attachment #647193 - Flags: review?(bpeterson)
(Assignee)

Comment 5

5 years ago
(In reply to Brendan Eich [:brendan] from comment #3)
> In general, locals use camelCase but not exclusively.

Indeed the existing memlen name was not camelCaps, and that caught my eye once I looked at the ifdef-related warning.

/be

Comment 6

5 years ago
Comment on attachment 647193 [details] [diff] [review]
like so

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

I failed to put _ on compressedLength_ to start.
Attachment #647193 - Flags: review?(bpeterson) → review+

Comment 7

5 years ago
https://hg.mozilla.org/integration/mozilla-inbound/rev/fb45f540d9ea
https://hg.mozilla.org/mozilla-central/rev/fb45f540d9ea
Status: NEW → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla17
You need to log in before you can comment on or make changes to this bug.