Date:2014-07-18 05:03:57 (4 months 11 days ago)
Author:Maarten ter Huurne
Commit:2effd1fc9955c7b89badeee6be8e1df44cc5fd44
Message:Made multi-line text drawing more efficient

Instead of splitting everything at once, split off one line at a time.
The code could be more compact but I want to avoid using substr on the
very common special case when a string contains no newlines.
Files: src/font.cpp (1 diff)

Change Details

src/font.cpp
6666        return;
6767    }
6868
69    if (text.find("\n", 0) == string::npos) {
69    size_t pos = text.find('\n', 0);
70    if (pos == string::npos) {
7071        writeLine(surface, text, x, y, halign, valign);
71        return;
72    }
73
74    vector<string> v;
75    split(v, text, "\n");
76
77    for (vector<string>::const_iterator it = v.begin(); it != v.end(); it++) {
78        writeLine(surface, *it, x, y, halign, valign);
79        y += lineSpacing;
72    } else {
73        size_t prev = 0;
74        do {
75            writeLine(surface, text.substr(prev, pos - prev),
76                    x, y, halign, valign);
77            y += lineSpacing;
78            prev = pos + 1;
79            pos = text.find('\n', prev);
80        } while (pos != string::npos);
81        writeLine(surface, text.substr(prev), x, y, halign, valign);
8082    }
8183}
8284

Archive Download the corresponding diff file



interactive