================
@@ -448,6 +530,41 @@ ContentCache &SourceManager::createMemBufferContentCache(
return *Entry;
}
+llvm::ErrorOr<llvm::TextEncodingConverter *>
+SourceManager::getOrCreateConverter(llvm::StringRef SourceEncoding) {
+ // Use getKnownEncoding to get normalized encoding names
+ std::optional<llvm::TextEncoding> SourceKnown =
+ llvm::TextEncodingConverter::getKnownEncoding(SourceEncoding);
+
+ if (SourceKnown && *SourceKnown == llvm::TextEncoding::UTF8)
+ return nullptr;
+
+ // Create a cache key using canonical encoding name
+ llvm::StringRef CacheKey =
+ SourceKnown
+ ? llvm::TextEncodingConverter::getKnownEncodingName(*SourceKnown)
+ : SourceEncoding;
----------------
cor3ntin wrote:
Actually a more efficient logic would be
- normalize the name
- check if there is a cached value for the normalized name, then return that
- or, create a encoding from the normalized name, if that succeed cache and
return
- otherwise fail
https://github.com/llvm/llvm-project/pull/206519
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits