QRegularExpression: do not mark as dirty on no-op setters
Quite some code in Qt takes a copy of a QRegularExpression and then
changes something on it (e.g. the case sensitivity) based on some
other criteria:
QRegularExpression copy = orig;
if (cond)
copy.setPatternOptions(copy.patternOptions() | CaseInsensitive);
use(copy);
This pattern can be found in QAIM, QString-related classes, and so on.
The "problem" is that if the attempted modification is a no-op, we'd
still invalidate the copy object (by detaching). Even if no detaches
are involved, setting the same pattern or options on a QRE object
shouldn't require a relatively expensive pattern recompile.
In summary: don't detach/mark a QRE object as dirty if a setter didn't
actually do a modification.
Change-Id: Iae0ab4a5e443e7285a83d3d7e0f1dcfd66e8d51d
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
parent
ab67a6b126
commit
78a8e561b2
|
|
@ -1452,6 +1452,8 @@ QString QRegularExpression::pattern() const
|
|||
*/
|
||||
void QRegularExpression::setPattern(const QString &pattern)
|
||||
{
|
||||
if (d->pattern == pattern)
|
||||
return;
|
||||
d.detach();
|
||||
d->isDirty = true;
|
||||
d->pattern = pattern;
|
||||
|
|
@ -1475,6 +1477,8 @@ QRegularExpression::PatternOptions QRegularExpression::patternOptions() const
|
|||
*/
|
||||
void QRegularExpression::setPatternOptions(PatternOptions options)
|
||||
{
|
||||
if (d->patternOptions == options)
|
||||
return;
|
||||
d.detach();
|
||||
d->isDirty = true;
|
||||
d->patternOptions = options;
|
||||
|
|
|
|||
Loading…
Reference in New Issue