| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package mojom | 5 package mojom |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 ) | 9 ) |
| 10 | 10 |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 } | 467 } |
| 468 | 468 |
| 469 /////////////////////////////////////////////////////////////////////// | 469 /////////////////////////////////////////////////////////////////////// |
| 470 /// Miscelleneous utilities | 470 /// Miscelleneous utilities |
| 471 /// ////////////////////////////////////////////////////////////////// | 471 /// ////////////////////////////////////////////////////////////////// |
| 472 | 472 |
| 473 func computeTypeKey(fullyQualifiedName string) (typeKey string) { | 473 func computeTypeKey(fullyQualifiedName string) (typeKey string) { |
| 474 if typeKey, ok := fqnToTypeKey[fullyQualifiedName]; ok == true { | 474 if typeKey, ok := fqnToTypeKey[fullyQualifiedName]; ok == true { |
| 475 return typeKey | 475 return typeKey |
| 476 } | 476 } |
| 477 » typeKey = fmt.Sprintf("%d", nextKey) | 477 » // TODO(rudominer) Until we understand better what the requirements are
for a type key |
| 478 » nextKey++ | 478 » // let's just use the reversed fully-qualified name as the type key. The
reason |
| 479 » // for the reversal is pragmatic: When debugging we can tell whether a s
tring |
| 480 » // is a type key or a fully-qualified-name |
| 481 » numBytes := len(fullyQualifiedName) |
| 482 » reversed := make([]byte, numBytes) |
| 483 » for i := 0; i < numBytes; i++ { |
| 484 » » reversed[i] = fullyQualifiedName[numBytes-i-1] |
| 485 » } |
| 486 » typeKey = string(reversed) |
| 479 fqnToTypeKey[fullyQualifiedName] = typeKey | 487 fqnToTypeKey[fullyQualifiedName] = typeKey |
| 480 return | 488 return |
| 481 } | 489 } |
| 482 | 490 |
| 483 var fqnToTypeKey map[string]string | 491 var fqnToTypeKey map[string]string |
| 484 var nextKey int | |
| 485 | 492 |
| 486 func init() { | 493 func init() { |
| 487 fqnToTypeKey = make(map[string]string) | 494 fqnToTypeKey = make(map[string]string) |
| 488 } | 495 } |
| OLD | NEW |