[wasm][cleanup] Use vector comparison instead of strncmp
{base::Vector} comparison is easier to read (IMO), and more performant, since {memcmp} will be used internally instead of {strncmp}. R=ahaas@chromium.org Bug: v8:10155 Change-Id: If92361688a85e96aa661d3e05cc9966e5ea2d04a Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2164796 Reviewed-by: Andreas Haas <ahaas@chromium.org> Commit-Queue: Clemens Backes <clemensb@chromium.org> Cr-Commit-Position: refs/heads/master@{#67605}
This commit is contained in:
parent
276eaea2c7
commit
8e7c6ec606
@ -35,11 +35,6 @@ constexpr char kCompilationHintsString[] = "compilationHints";
|
||||
constexpr char kDebugInfoString[] = ".debug_info";
|
||||
constexpr char kExternalDebugInfoString[] = ".external_debug_info";
|
||||
|
||||
template <size_t N>
|
||||
constexpr size_t num_chars(const char (&)[N]) {
|
||||
return N - 1; // remove null character at end.
|
||||
}
|
||||
|
||||
const char* ExternalKindName(ImportExportKindCode kind) {
|
||||
switch (kind) {
|
||||
case kExternalFunction:
|
||||
@ -167,30 +162,21 @@ SectionCode IdentifyUnknownSectionInternal(Decoder* decoder) {
|
||||
static_cast<int>(section_name_start - decoder->start()),
|
||||
string.length() < 20 ? string.length() : 20, section_name_start);
|
||||
|
||||
if (string.length() == num_chars(kNameString) &&
|
||||
strncmp(reinterpret_cast<const char*>(section_name_start), kNameString,
|
||||
num_chars(kNameString)) == 0) {
|
||||
return kNameSectionCode;
|
||||
} else if (string.length() == num_chars(kSourceMappingURLString) &&
|
||||
strncmp(reinterpret_cast<const char*>(section_name_start),
|
||||
kSourceMappingURLString,
|
||||
num_chars(kSourceMappingURLString)) == 0) {
|
||||
return kSourceMappingURLSectionCode;
|
||||
} else if (string.length() == num_chars(kCompilationHintsString) &&
|
||||
strncmp(reinterpret_cast<const char*>(section_name_start),
|
||||
kCompilationHintsString,
|
||||
num_chars(kCompilationHintsString)) == 0) {
|
||||
return kCompilationHintsSectionCode;
|
||||
} else if (string.length() == num_chars(kDebugInfoString) &&
|
||||
strncmp(reinterpret_cast<const char*>(section_name_start),
|
||||
kDebugInfoString, num_chars(kDebugInfoString)) == 0) {
|
||||
return kDebugInfoSectionCode;
|
||||
} else if (string.length() == num_chars(kExternalDebugInfoString) &&
|
||||
strncmp(reinterpret_cast<const char*>(section_name_start),
|
||||
kExternalDebugInfoString,
|
||||
num_chars(kExternalDebugInfoString)) == 0) {
|
||||
return kExternalDebugInfoSectionCode;
|
||||
using SpecialSectionPair = std::pair<Vector<const char>, SectionCode>;
|
||||
static constexpr SpecialSectionPair kSpecialSections[]{
|
||||
{StaticCharVector(kNameString), kNameSectionCode},
|
||||
{StaticCharVector(kSourceMappingURLString), kSourceMappingURLSectionCode},
|
||||
{StaticCharVector(kCompilationHintsString), kCompilationHintsSectionCode},
|
||||
{StaticCharVector(kDebugInfoString), kDebugInfoSectionCode},
|
||||
{StaticCharVector(kExternalDebugInfoString),
|
||||
kExternalDebugInfoSectionCode}};
|
||||
|
||||
auto name_vec =
|
||||
Vector<const char>::cast(VectorOf(section_name_start, string.length()));
|
||||
for (auto& special_section : kSpecialSections) {
|
||||
if (name_vec == special_section.first) return special_section.second;
|
||||
}
|
||||
|
||||
return kUnknownSectionCode;
|
||||
}
|
||||
} // namespace
|
||||
|
Loading…
Reference in New Issue
Block a user