Bug 850536: Only get the chars of a string once in FlattenSubstrings, r=sstangl