~compiz-team/compiz/compiz.fix_1088399

« back to all changes in this revision

Viewing changes to src/screen.cpp

Minor Performance Optimizations:

* Return ASAP./Prevent executing any unnecessary operations if we return.
* Used De Morgan's laws to merge and simplify if statements.

Other Changes:

* C++ Style: Declared iterator variables inside the for loops they are used in.
* No logic changes have been made.

Approved by Daniel van Vugt.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1190
1190
void
1191
1191
PrivateScreen::handleSelectionRequest (XEvent *event)
1192
1192
{
1193
 
    XSelectionEvent reply;
1194
 
 
1195
1193
    if (wmSnSelectionWindow != event->xselectionrequest.owner ||
1196
1194
        wmSnAtom != event->xselectionrequest.selection)
1197
1195
        return;
1198
1196
 
 
1197
    XSelectionEvent reply;
 
1198
 
1199
1199
    reply.type      = SelectionNotify;
1200
1200
    reply.display   = dpy;
1201
1201
    reply.requestor = event->xselectionrequest.requestor;
1691
1691
 
1692
1692
    if (XGetWMProtocols (dpy, id, &protocol, &count))
1693
1693
    {
1694
 
        int  i;
1695
 
 
1696
 
        for (i = 0; i < count; i++)
 
1694
        for (int i = 0; i < count; i++)
1697
1695
        {
1698
1696
            if (protocol[i] == Atoms::wmDeleteWindow)
1699
1697
                protocols |= CompWindowProtocolDeleteMask;
1877
1875
PrivateScreen::setDesktopHints ()
1878
1876
{
1879
1877
    unsigned long *data;
1880
 
    int           dSize, offset, hintSize;
1881
 
    unsigned int  i;
1882
1878
 
1883
 
    dSize = nDesktop * 2 + nDesktop * 2 + nDesktop * 4 + 1;
 
1879
    int dSize = nDesktop * 2 + nDesktop * 2 + nDesktop * 4 + 1;
1884
1880
 
1885
1881
    data = (unsigned long *) malloc (sizeof (unsigned long) * dSize);
1886
1882
    if (!data)
1887
1883
        return;
1888
1884
 
1889
 
    offset   = 0;
1890
 
    hintSize = nDesktop * 2;
 
1885
    unsigned int  i;
 
1886
    int offset   = 0;
 
1887
    int hintSize = nDesktop * 2;
1891
1888
 
1892
1889
    for (i = 0; i < nDesktop; i++)
1893
1890
    {
2228
2225
        { 0, -1,   1, -1,   0,  2,   0,  2 }, /* bottom-left */
2229
2226
        { 1, -1,   1, -1,   0,  2,   0,  2 }  /* bottom-right */
2230
2227
    };
2231
 
    int i;
2232
2228
 
2233
 
    for (i = 0; i < SCREEN_EDGE_NUM; i++)
 
2229
    for (int i = 0; i < SCREEN_EDGE_NUM; i++)
2234
2230
    {
2235
2231
        if (screenEdge[i].id)
2236
2232
            XMoveResizeWindow (dpy, screenEdge[i].id,
3477
3473
 
3478
3474
    if (action->edgeMask ())
3479
3475
    {
3480
 
        int i;
3481
 
 
3482
 
        for (i = 0; i < SCREEN_EDGE_NUM; i++)
 
3476
        for (int i = 0; i < SCREEN_EDGE_NUM; i++)
3483
3477
            if (action->edgeMask () & (1 << i))
3484
3478
                privateScreen.enableEdge (i);
3485
3479
    }
3492
3486
void
3493
3487
CompScreenImpl::removeAction (CompAction *action)
3494
3488
{
3495
 
    if (!privateScreen.initialized)
3496
 
        return;
3497
 
 
3498
 
    if (!action->active ())
 
3489
    if (!(privateScreen.initialized || action->active ()))
3499
3490
        return;
3500
3491
 
3501
3492
    grabManager.setCurrentState(action->state());
3508
3499
 
3509
3500
    if (action->edgeMask ())
3510
3501
    {
3511
 
        int i;
3512
 
 
3513
 
        for (i = 0; i < SCREEN_EDGE_NUM; i++)
 
3502
        for (int i = 0; i < SCREEN_EDGE_NUM; i++)
3514
3503
            if (action->edgeMask () & (1 << i))
3515
3504
                privateScreen.disableEdge (i);
3516
3505
    }
3971
3960
void
3972
3961
PrivateScreen::setNumberOfDesktops (unsigned int nDesktop)
3973
3962
{
3974
 
    if (nDesktop < 1 || nDesktop >= 0xffffffff)
3975
 
        return;
3976
 
 
3977
 
    if (nDesktop == this->nDesktop)
 
3963
    if (nDesktop < 1 || nDesktop >= 0xffffffff || nDesktop == this->nDesktop)
3978
3964
        return;
3979
3965
 
3980
3966
    if (currentDesktop >= nDesktop)
3990
3976
void
3991
3977
PrivateScreen::setCurrentDesktop (unsigned int desktop)
3992
3978
{
3993
 
    if (desktop >= nDesktop)
3994
 
        return;
3995
 
 
3996
 
    if (desktop == currentDesktop)
 
3979
    if (desktop >= nDesktop || desktop == currentDesktop)
3997
3980
        return;
3998
3981
 
3999
3982
    currentDesktop = desktop;
4135
4118
{
4136
4119
    CompActiveWindowHistory *history = &this->history[currentHistory_];
4137
4120
    Window                  tmp, next = id;
4138
 
    int                     i;
4139
4121
 
4140
4122
    /* walk and move history */
4141
 
    for (i = 0; i < ACTIVE_WINDOW_HISTORY_SIZE; i++)
 
4123
    for (int i = 0; i < ACTIVE_WINDOW_HISTORY_SIZE; i++)
4142
4124
    {
4143
4125
        tmp = history->id[i];
4144
4126
        history->id[i] = next;