17
17
#ifndef SWIFT_LOCALIZATIONFORMAT_H
18
18
#define SWIFT_LOCALIZATIONFORMAT_H
19
19
20
+ #include " llvm/ADT/Hashing.h"
20
21
#include " llvm/ADT/STLExtras.h"
21
22
#include " llvm/ADT/StringRef.h"
22
23
#include " llvm/Bitstream/BitstreamReader.h"
23
- #include " llvm/Support/DJB.h"
24
24
#include " llvm/Support/EndianStream.h"
25
25
#include " llvm/Support/MemoryBuffer.h"
26
26
#include " llvm/Support/OnDiskHashTable.h"
@@ -42,27 +42,27 @@ using namespace llvm::support;
42
42
43
43
class LocalizationWriterInfo {
44
44
public:
45
- using key_type = std::string ;
46
- using key_type_ref = key_type ;
45
+ using key_type = uint32_t ;
46
+ using key_type_ref = const uint32_t & ;
47
47
using data_type = std::string;
48
- using data_type_ref = data_type ;
48
+ using data_type_ref = llvm::StringRef ;
49
49
using hash_value_type = uint32_t ;
50
50
using offset_type = uint32_t ;
51
51
52
- hash_value_type ComputeHash (key_type_ref key) { return llvm::djbHash (key); }
52
+ hash_value_type ComputeHash (key_type_ref key) { return llvm::hash_code (key); }
53
53
54
54
std::pair<offset_type, offset_type> EmitKeyDataLength (llvm::raw_ostream &out,
55
55
key_type_ref key,
56
56
data_type_ref data) {
57
- offset_type keyLength = static_cast <offset_type>(key.size ());
58
57
offset_type dataLength = static_cast <offset_type>(data.size ());
59
- endian::write<offset_type>(out, keyLength, little);
60
58
endian::write<offset_type>(out, dataLength, little);
61
- return {keyLength, dataLength};
59
+ // No need to write the key length; it's constant.
60
+ return {sizeof (key_type), dataLength};
62
61
}
63
62
64
63
void EmitKey (llvm::raw_ostream &out, key_type_ref key, unsigned len) {
65
- out << key;
64
+ assert (len == sizeof (key_type));
65
+ endian::write<key_type>(out, key, little);
66
66
}
67
67
68
68
void EmitData (llvm::raw_ostream &out, key_type_ref key, data_type_ref data,
@@ -73,38 +73,40 @@ class LocalizationWriterInfo {
73
73
74
74
class LocalizationReaderInfo {
75
75
public:
76
- using internal_key_type = llvm::StringRef ;
77
- using external_key_type = internal_key_type ;
76
+ using internal_key_type = uint32_t ;
77
+ using external_key_type = swift::DiagID ;
78
78
using data_type = llvm::StringRef;
79
79
using hash_value_type = uint32_t ;
80
80
using offset_type = uint32_t ;
81
81
82
- internal_key_type GetInternalKey (external_key_type key) { return key; }
82
+ internal_key_type GetInternalKey (external_key_type key) {
83
+ return static_cast <internal_key_type>(key);
84
+ }
83
85
84
- external_key_type GetExternalKey (internal_key_type key) { return key; }
86
+ external_key_type GetExternalKey (internal_key_type key) {
87
+ return static_cast <external_key_type>(key);
88
+ }
85
89
86
90
static bool EqualKey (internal_key_type lhs, internal_key_type rhs) {
87
91
return lhs == rhs;
88
92
}
89
93
90
94
hash_value_type ComputeHash (internal_key_type key) {
91
- return llvm::djbHash (key);
95
+ return llvm::hash_code (key);
92
96
}
93
97
94
98
static std::pair<offset_type, offset_type>
95
99
ReadKeyDataLength (const unsigned char *&data) {
96
- offset_type keyLength =
97
- endian::readNext<offset_type, little, unaligned>(data);
98
100
offset_type dataLength =
99
101
endian::readNext<offset_type, little, unaligned>(data);
100
- return {keyLength , dataLength};
102
+ return {sizeof ( uint32_t ) , dataLength};
101
103
}
102
104
103
105
internal_key_type ReadKey (const unsigned char *data, offset_type length) {
104
- return internal_key_type (( const char *)data, length );
106
+ return endian::readNext< internal_key_type, little, unaligned>(data );
105
107
}
106
108
107
- data_type ReadData (llvm::StringRef Key, const unsigned char *data,
109
+ data_type ReadData (internal_key_type Key, const unsigned char *data,
108
110
offset_type length) {
109
111
return data_type ((const char *)data, length);
110
112
}
@@ -119,10 +121,10 @@ class SerializedLocalizationWriter {
119
121
// / file.
120
122
// /
121
123
// / \param id The identifier associated with the given diagnostic message e.g.
122
- // / 'cannot_convert_argument'.
123
- // / \param translation The localized diagnostic
124
- // / message for the given identifier.
125
- void insert (llvm::StringRef id, llvm::StringRef translation);
124
+ // / 'cannot_convert_argument'.
125
+ // / \param translation The localized diagnostic message for the given
126
+ // / identifier.
127
+ void insert (swift::DiagID id, llvm::StringRef translation);
126
128
127
129
// / Write out previously inserted diagnostic translations into the given
128
130
// / location.
@@ -158,7 +160,7 @@ class YAMLLocalizationProducer final : public LocalizationProducer {
158
160
// / maintained by this producer, callback gets each translation
159
161
// / with its unique identifier.
160
162
void forEachAvailable (
161
- llvm::function_ref<void (uint32_t , llvm::StringRef)> callback) const ;
163
+ llvm::function_ref<void (swift::DiagID , llvm::StringRef)> callback) const ;
162
164
};
163
165
164
166
class SerializedLocalizationProducer final : public LocalizationProducer {
0 commit comments