~compiz-team/compiz/compiz.fix_1088399

« back to all changes in this revision

Viewing changes to compizconfig/libcompizconfig/src/compiz.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:
349
349
 
350
350
    if (num)
351
351
    {
352
 
        int j;
353
 
        for (j = 0; j < num; j++)
 
352
        for (int j = 0; j < num; j++)
354
353
        {
355
354
            CCSSettingValue *val;
356
355
            val = (CCSSettingValue *) calloc (1, sizeof (CCSSettingValue));
786
785
addStringExtensionFromPB (CCSPlugin * plugin,
787
786
                          const ExtensionMetadata & extensionPB)
788
787
{
789
 
    int j;
790
788
    CCSStrExtension *extension;
791
789
 
792
790
    extension = (CCSStrExtension *) calloc (1, sizeof (CCSStrExtension));
808
806
        return;
809
807
    }
810
808
 
811
 
    for (j = 0; j < numRestrictions; j++)
 
809
    for (int j = 0; j < numRestrictions; j++)
812
810
    {
813
811
        const OptionMetadata::StringRestriction & restrictionPB =
814
812
            extensionPB.str_restriction (j);
829
827
initStringExtensionsFromPB (CCSPlugin * plugin,
830
828
                            const PluginMetadata & pluginPB)
831
829
{
832
 
    int numExtensions, i;
 
830
    int numExtensions;
833
831
 
834
832
    numExtensions = pluginPB.extension_size ();
835
 
    for (i = 0; i < numExtensions; i++)
 
833
    for (int i = 0; i < numExtensions; i++)
836
834
        addStringExtensionFromPB (plugin, pluginPB.extension (i));
837
835
}
838
836
 
1111
1109
    xmlXPathContextPtr xpathCtx;
1112
1110
    xmlNode **rv = NULL;
1113
1111
    int size;
1114
 
    int i;
1115
1112
 
1116
1113
    *num = 0;
1117
1114
 
1146
1143
    }
1147
1144
    *num = size;
1148
1145
 
1149
 
    for (i = 0; i < size; i++)
 
1146
    for (int i = 0; i < size; i++)
1150
1147
        rv[i] = xpathObj->nodesetval->nodeTab[i];
1151
1148
 
1152
1149
    xmlXPathFreeObject (xpathObj);
1554
1551
    nodes = getNodesFromXPath (node->doc, node, "value", &num);
1555
1552
    if (num)
1556
1553
    {
1557
 
        int j;
1558
 
        for (j = 0; j < num; j++)
 
1554
        for (int j = 0; j < num; j++)
1559
1555
        {
1560
1556
            void *valuePBv = NULL;
1561
1557
#ifdef USE_PROTOBUF
1651
1647
        if (num)
1652
1648
        {
1653
1649
            char *name;
1654
 
            int j;
1655
 
            for (j = 0; j < num; j++)
 
1650
            for (int j = 0; j < num; j++)
1656
1651
            {
1657
1652
                value = getStringFromXPath (node->doc, nodes[j],
1658
1653
                                            "value/child::text()");
1792
1787
        nodes = getNodesFromXPath (node->doc, node, "restriction", &num);
1793
1788
        if (num)
1794
1789
        {
1795
 
            int j;
1796
1790
            char *name, *value;
1797
 
            for (j = 0; j < num; j++)
 
1791
            for (int j = 0; j < num; j++)
1798
1792
            {
1799
1793
#ifdef USE_PROTOBUF
1800
1794
                OptionMetadata::StringRestriction * strRestrictionPB = NULL;
2295
2289
         &num);
2296
2290
    if (num)
2297
2291
    {
2298
 
        int i;
2299
 
        for (i = 0; i < num; i++)
 
2292
        for (int i = 0; i < num; i++)
2300
2293
        {
2301
2294
            void *optionPBv = NULL;
2302
2295
    #ifdef USE_PROTOBUF
2333
2326
 
2334
2327
    if (num)
2335
2328
    {
2336
 
        int i;
2337
 
        for (i = 0; i < num; i++)
 
2329
        for (int i = 0; i < num; i++)
2338
2330
        {
2339
2331
            char *value = stringFromNodeDef (nodes[i], "child::text()", NULL);
2340
2332
 
2365
2357
                               void * extensionPBv)
2366
2358
{
2367
2359
    xmlNode **nodes;
2368
 
    int num, j;
 
2360
    int num;
2369
2361
    CCSStrExtension *extension;
2370
2362
    char *name;
2371
2363
    char *value;
2402
2394
        return;
2403
2395
    }
2404
2396
 
2405
 
    for (j = 0; j < num; j++)
 
2397
    for (int j = 0; j < num; j++)
2406
2398
    {
2407
2399
        value = getStringFromXPath (node->doc, nodes[j], "value/child::text()");
2408
2400
        if (value)
2440
2432
                                  void * pluginPBv)
2441
2433
{
2442
2434
    xmlNode **nodes;
2443
 
    int num, i;
 
2435
    int num;
2444
2436
    nodes = getNodesFromXPath (node->doc, node, "/compiz/*/extension", &num);
2445
2437
 
2446
 
    for (i = 0; i < num; i++)
 
2438
    for (int i = 0; i < num; i++)
2447
2439
    {
2448
2440
        void *extensionPBv = NULL;
2449
2441
#ifdef USE_PROTOBUF
2952
2944
loadPluginsFromXMLFiles (CCSContext * context, char *path)
2953
2945
{
2954
2946
    struct dirent **nameList;
2955
 
    int nFile, i;
 
2947
    int nFile;
2956
2948
 
2957
2949
    if (!path)
2958
2950
        return;
2968
2960
    if (nFile <= 0)
2969
2961
        return;
2970
2962
 
2971
 
    for (i = 0; i < nFile; i++)
 
2963
    for (int i = 0; i < nFile; i++)
2972
2964
    {
2973
2965
        loadPluginFromXMLFile (context, nameList[i]->d_name, path);
2974
2966
        free (nameList[i]);
3028
3020
loadPluginsFromName (CCSContext * context, char *path)
3029
3021
{
3030
3022
    struct dirent **nameList;
3031
 
    int nFile, i;
 
3023
    int nFile;
3032
3024
 
3033
3025
    if (!path)
3034
3026
        return;
3037
3029
    if (nFile <= 0)
3038
3030
        return;
3039
3031
 
3040
 
    for (i = 0; i < nFile; i++)
 
3032
    for (int i = 0; i < nFile; i++)
3041
3033
    {
3042
3034
        char name[1024];
3043
3035
        sscanf (nameList[i]->d_name, "lib%s", name);