<div dir="ltr">We can do better, but not in this way (see my other email, this will generate wrong answers) , and it's IMHO not worth it.<div><br></div><div>You can avoid doing the replacement directly by using the match start and end, but if you do, we either have to mess with the loop quite a bit.</div><div>Even if we stop using finditer (because we are replacing the string it is using as it goes, and it does not keep up to date) and use match directly, we have to offset where it starts looking for matches by the amount of text we've added by converting to var defs/uses, etc, or risk false matches.</div><div><br></div><div><br></div><div>None of this is worth it compared to keeping it simple like I did, imho.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 6, 2017 at 9:26 AM, bryant via Phabricator <span dir="ltr"><<a href="mailto:reviews@reviews.llvm.org" target="_blank">reviews@reviews.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">bryant added inline comments.<br>
<span class=""><br>
<br>
================<br>
Comment at: utils/update_test_checks.py:<wbr>176<br>
</span><span class="">+      if match.group(1) in vars_seen:<br>
+        line = line.replace('%' + match.group(1), get_value_use(match.group(1)), 1)<br>
+        continue<br>
</span>----------------<br>
<span class="">bryant wrote:<br>
> You're limiting the number of replaced uses to 1. Can a line have more than one use?<br>
</span>Just to clarify, what I meant is that you can do a lot better than manually replacing one at a time:<br>
<br>
```<br>
def genericize_check_lines(lines):<br>
    def ssaify(match):<br>
        v = match.group(1)<br>
        if v in var_seen:<br>
            rv = get_value_use(v)<br>
        else:<br>
            vars_seen.add('%' + v)<br>
            rv = get_value_definition(v)<br>
        return rv<br>
    for line in lines:<br>
        scrubbed_line = ...<br>
        new_ine = IRVALUE_RE.sub(ssaify, scrubbed_line)<br>
    ...<br>
```<br>
<br>
I suspect that underneath, `_sre` is building the replacement string incrementally, so it won't be quadratic.<br>
<br>
<br>
<a href="https://reviews.llvm.org/D28384" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D28384</a><br>
<br>
<br>
<br>
</blockquote></div><br></div>