Closed Bug 778627 Opened 12 years ago Closed 12 years ago

recent warning abatement

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla17

People

(Reporter: brendan, Assigned: brendan)

Details

Attachments

(1 file, 1 obsolete file)

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)
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 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.
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
Attached patch like soSplinter Review
Attachment #647068 - Attachment is obsolete: true
Attachment #647068 - Flags: review?(dmandelin)
Attachment #647193 - Flags: review?(bpeterson)
(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 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+
https://hg.mozilla.org/mozilla-central/rev/fb45f540d9ea
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla17
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: