| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library dart2js.util; | 5 library dart2js.util; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'util_implementation.dart'; | 8 import 'util_implementation.dart'; |
| 9 import 'characters.dart'; | 9 import 'characters.dart'; |
| 10 | 10 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 | 187 |
| 188 int longestCommonPrefixLength(List a, List b) { | 188 int longestCommonPrefixLength(List a, List b) { |
| 189 int index = 0; | 189 int index = 0; |
| 190 for ( ; index < a.length && index < b.length; index++) { | 190 for ( ; index < a.length && index < b.length; index++) { |
| 191 if (a[index] != b[index]) { | 191 if (a[index] != b[index]) { |
| 192 break; | 192 break; |
| 193 } | 193 } |
| 194 } | 194 } |
| 195 return index; | 195 return index; |
| 196 } | 196 } |
| 197 |
| 198 /// Returns [suggestedName] if it is not in [usedNames]. Otherwise concatenates |
| 199 /// the smallest number that makes it not appear in [usedNames]. |
| 200 /// |
| 201 /// Adds the result to [usedNames]. |
| 202 String makeUnique(String suggestedName, Set<String> usedNames) { |
| 203 String result = suggestedName; |
| 204 if (usedNames.contains(suggestedName)) { |
| 205 int counter = 0; |
| 206 while (usedNames.contains(result)) { |
| 207 counter++; |
| 208 result = "$suggestedName$counter"; |
| 209 } |
| 210 } |
| 211 usedNames.add(result); |
| 212 return result; |
| 213 } |
| OLD | NEW |