Optimize ComparisonCompactor

Rewrite code for better readability, introduce thread-safety, eliminate duplicate computation of prefix/suffix strings.