Open
Bug 446288
Opened 16 years ago
Updated 2 years ago
(minor) Clean up <messengerdnd.js>
Categories
(MailNews Core :: Backend, defect)
MailNews Core
Backend
Tracking
(Not tracked)
ASSIGNED
mozilla1.9.1a2
People
(Reporter: sgautherie, Assigned: sgautherie)
References
(Depends on 1 open bug, )
Details
Attachments
(1 file)
22.79 KB,
patch
|
standard8
:
review-
|
Details | Diff | Splinter Review |
While working on bug 370904,
I noticed some clean up to do / look into.
Assignee | ||
Comment 1•16 years ago
|
||
[Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.9.0.2pre) Gecko/2008071502 SeaMonkey/2.0a1pre] (nightly) (W2Ksp4)
I'm using SM, but this file is shared with TB.
Severity: minor → trivial
Assignee | ||
Comment 2•16 years ago
|
||
[Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.9.0.2pre) Gecko/2008071502 SeaMonkey/2.0a1pre] (nightly) (W2Ksp4)
*Remove lots of superfluous/useless vars.
*Add a few.
*Do a few rewrite.
NB: This cleans up the way for (2+) following patches.
Assignee: nobody → sgautherie.bz
Status: NEW → ASSIGNED
Attachment #330686 -
Flags: superreview?(bienvenu)
Attachment #330686 -
Flags: review?(bugzilla)
Comment 3•16 years ago
|
||
Comment on attachment 330686 [details] [diff] [review]
(Av1) |var ...| cleanup ++
>- var targetUri = targetResource.Value;
> var targetFolder = targetResource.QueryInterface(Components.interfaces.nsIMsgFolder);
> var targetServer = targetFolder.server;
>- var sourceServer;
>- var sourceResource;
>+ var sourceServer = null;
>+ var sourceResource = null;
>+ var sourceFolder;
>
>- for (var i = 0; i < dragSession.numDropItems; i++)
>+ const numDropItems = dragSession.numDropItems;
>+ var dataFlavor, dataObj, len, sourceUri;
I see no advantage to pulling these out of the loop.
>+ for (var i = 0; i < numDropItems; ++i)
> {
> dragSession.getData (trans, i);
>- var dataObj = new Object();
>- var dataFlavor = new Object();
>- var len = new Object();
>+ len = dataObj = dataFlavor = {};
These are not equivalent.
>- if (dataFlavor.value == "text/x-moz-message")
>+ dataFlavor = dataFlavor.value;
>+ if (dataFlavor == "text/x-moz-message")
> {
I don't see any advantage to doing this replacement. dataFlavor is a javascript object, accessing it is not going to take lots of time.
>- sourceResource = null;
So now you've taken this outside the loop, if it gets used once round the loop the first time, and not the second time, then it won't be null the second time. I'm not sure if we'd ever get to that case, but it could lead to errors from future modifications because its no longer being set to null.
>+ sourceFolder = sourceResource.QueryInterface(Components.interfaces.nsIMsgFolder);
>
>- // don't allow dragging news folder (newsgroup) to server folder
>- if (targetFolder.isServer)
>+ // don't allow dragging news folder (newsgroup) to other account
>+ // or server folder.
>+ if (targetFolder.rootFolder != sourceFolder.rootFolder ||
>+ targetFolder.isServer)
>+ {
> return false;
>+ }
Please don't put braces around one line statements.
> // don't allow dragging news folder (newsgroup) to before/after itself
> index += orientation;
> if (index < folderTree.view.rowCount) {
>- targetResource = GetFolderResource(folderTree, index);
>-
>- if (targetResource == sourceResource)
>+ if (GetFolderResource(folderTree, index) == sourceResource)
> return false;
I don't see why you're not using the targetResource that's set up at the start.
Attachment #330686 -
Flags: superreview?(bienvenu)
Attachment #330686 -
Flags: review?(bugzilla)
Attachment #330686 -
Flags: review-
Assignee | ||
Comment 4•16 years ago
|
||
(In reply to comment #3)
> (From update of attachment 330686 [details] [diff] [review])
> >+ var dataFlavor, dataObj, len, sourceUri;
>
> I see no advantage to pulling these out of the loop.
I assumed it might save some "|var| processing".
Does it not ?
> >- var dataObj = new Object();
> >- var dataFlavor = new Object();
> >- var len = new Object();
> >+ len = dataObj = dataFlavor = {};
>
> These are not equivalent.
I found both values when I did an MXR search,
and assumed the latter was "equivalent but simpler".
Is it not ?
> >+ dataFlavor = dataFlavor.value;
>
> I don't see any advantage to doing this replacement. dataFlavor is a javascript
> object, accessing it is not going to take lots of time.
Second thought ... agreed.
> >- sourceResource = null;
>
> So now you've taken this outside the loop, if it gets used once round the loop
> the first time, and not the second time, then it won't be null the second time.
(line removal part)
Actually, in the current code, this assignment is useless.
Anyway, this case can't loop, as there is a |break;| at the end of its block.
> I'm not sure if we'd ever get to that case, but it could lead to errors from
> future modifications because its no longer being set to null.
(assignment move part)
And my next patch will need the var to be initialized.
> >+ if (targetFolder.rootFolder != sourceFolder.rootFolder ||
> >+ targetFolder.isServer)
> >+ {
> > return false;
> >+ }
>
> Please don't put braces around one line statements.
It was only to make it clearer after the multi-line if, but as you wish.
> > index += orientation;
> > if (index < folderTree.view.rowCount) {
> >+ if (GetFolderResource(folderTree, index) == sourceResource)
> > return false;
>
> I don't see why you're not using the targetResource that's set up at the start.
Oh, I too wondered about this code the first time I read it:
the answer is that |index| has just got a new value ;->
Target Milestone: mozilla1.9.1a1 → mozilla1.9.1a2
Assignee | ||
Comment 5•16 years ago
|
||
Let's complete the cleanup, before looking into the exception bugs.
Updated•16 years ago
|
Product: Core → MailNews Core
Assignee | ||
Comment 6•16 years ago
|
||
Comment on attachment 330686 [details] [diff] [review]
(Av1) |var ...| cleanup ++
Reminder: Bug 356295 bitrotted the |BeginDragTree()| part...
Comment 7•16 years ago
|
||
Serge, possible to drive this and bug 446292 in for TB3?
Assignee | ||
Comment 8•16 years ago
|
||
(In reply to comment #4)
Mark, can you answer my comment 4 questions?
> > >- var dataObj = new Object();
> > >- var dataFlavor = new Object();
> > >- var len = new Object();
> > >+ len = dataObj = dataFlavor = {};
> >
> > These are not equivalent.
>
> I found both values when I did an MXR search,
> and assumed the latter was "equivalent but simpler".
> Is it not ?
Ah, I guess I can use |{}| but I still need 3 distinct initializations, right?
Comment 9•13 years ago
|
||
(In reply to Serge Gautherie (:sgautherie) from comment #8)
> (In reply to comment #4)
>
> Mark, can you answer my comment 4 questions?
>
>
> > > >- var dataObj = new Object();
> > > >- var dataFlavor = new Object();
> > > >- var len = new Object();
> > > >+ len = dataObj = dataFlavor = {};
> > >
> > > These are not equivalent.
> >
> > I found both values when I did an MXR search,
> > and assumed the latter was "equivalent but simpler".
> > Is it not ?
>
> Ah, I guess I can use |{}| but I still need 3 distinct initializations,
> right?
Yes, because otherwise you'd end up with all of them trying to use the same object.
Updated•2 years ago
|
Severity: trivial → S4
You need to log in
before you can comment on or make changes to this bug.
Description
•