Changeset 704 for cpp/frams/param


Ignore:
Timestamp:
09/27/17 12:17:31 (7 years ago)
Author:
Maciej Komosinski
Message:

ParamInterface::getText() improved: removed pointless iteration when no ~enum is present (caused major performance hit for big integer values)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/param/param.cpp

    r659 r704  
    702702}
    703703
    704 SString ParamInterface::getText(int i)
     704SString ParamInterface::getText(int i) //find the current enum text or call get(i) if not enum
    705705{
    706706        const char *t;
    707         if ((*(t = type(i))) == 'd')
     707        if (((*(t = type(i))) == 'd') && (strchr(t, '~')!=NULL)) //type is int and contains enum labels
    708708        {
    709709                paInt mn, mx, def;
     
    712712                {
    713713                        if (value > mx)
    714                                 return get(i);
     714                                return get(i);//unexpected value of out bounds (should never happen) -> fallback
    715715                        value -= mn;
    716716                }
    717                 if (value < 0) return get(i);
    718                 for (; value >= 0; value--) if (t) t = strchr(t + 1, '~');
    719                 if (t)
     717                if (value < 0) return get(i); //unexpected value of out bounds (should never happen) -> fallback
     718                // now value is 0-based index of ~text
     719                for (; value >= 0; value--) if (t) t = strchr(t + 1, '~'); else break;
     720                if (t) // found n-th ~text in type description (else: not enough ~texts in type description)
    720721                {
    721722                        t++;
     
    725726                }
    726727        }
    727         return get(i);
     728        return get(i); //fallback - return int value as string
    728729}
    729730
Note: See TracChangeset for help on using the changeset viewer.