Last Comment Bug 778627 - recent warning abatement
: recent warning abatement
Status: RESOLVED FIXED
:
Product: Core
Classification: Components
Component: JavaScript Engine (show other bugs)
: Trunk
: All All
: -- normal (vote)
: mozilla17
Assigned To: Brendan Eich [:brendan]
:
Mentors:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-07-29 22:39 PDT by Brendan Eich [:brendan]
Modified: 2012-07-31 06:12 PDT (History)
3 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
fix warnings on Mac shell builds, use canonical names (6.10 KB, patch)
2012-07-29 22:39 PDT, Brendan Eich [:brendan]
no flags Details | Diff | Splinter Review
like so (7.47 KB, patch)
2012-07-30 08:57 PDT, Brendan Eich [:brendan]
benjamin: review+
Details | Diff | Splinter Review

Description Brendan Eich [:brendan] 2012-07-29 22:39:23 PDT
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
Comment 1 Brendan Eich [:brendan] 2012-07-29 22:45:14 PDT
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 :Benjamin Peterson 2012-07-29 23:12:59 PDT
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.
Comment 3 Brendan Eich [:brendan] 2012-07-30 08:52:01 PDT
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
Comment 4 Brendan Eich [:brendan] 2012-07-30 08:57:05 PDT
Created attachment 647193 [details] [diff] [review]
like so
Comment 5 Brendan Eich [:brendan] 2012-07-30 09:05:23 PDT
(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 :Benjamin Peterson 2012-07-30 10:10:26 PDT
Comment on attachment 647193 [details] [diff] [review]
like so

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

I failed to put _ on compressedLength_ to start.
Comment 8 Ed Morley [:emorley] 2012-07-31 06:12:13 PDT
https://hg.mozilla.org/mozilla-central/rev/fb45f540d9ea

Note You need to log in before you can comment on or make changes to this bug.