mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:17:36 +00:00
Kernel: Fixed behavior of repeated calls to register_string
Previously register_string would return incorrect values when called multiple times with the same input. This patch makes this function return the same index, identical strings. This change was required, as this functionality is now being used with read syscall profiling, (#12465), which uses 'register_string' to registers file path on every read syscall.
This commit is contained in:
parent
697e1810bf
commit
d01d754b83
2 changed files with 20 additions and 6 deletions
|
@ -199,8 +199,17 @@ ErrorOr<void> PerformanceEventBuffer::to_json_impl(Serializer& object) const
|
|||
{
|
||||
{
|
||||
auto strings = TRY(object.add_array("strings"));
|
||||
for (auto const& it : m_strings)
|
||||
TRY(strings.add(it->view()));
|
||||
Vector<KString*> strings_sorted_by_index;
|
||||
TRY(strings_sorted_by_index.try_resize(m_strings.size()));
|
||||
|
||||
for (auto& entry : m_strings) {
|
||||
strings_sorted_by_index[entry.value] = const_cast<Kernel::KString*>(entry.key.ptr());
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < m_strings.size(); i++) {
|
||||
TRY(strings.add(strings_sorted_by_index[i]->view()));
|
||||
}
|
||||
|
||||
TRY(strings.finish());
|
||||
}
|
||||
|
||||
|
@ -361,9 +370,14 @@ ErrorOr<void> PerformanceEventBuffer::add_process(const Process& process, Proces
|
|||
|
||||
ErrorOr<FlatPtr> PerformanceEventBuffer::register_string(NonnullOwnPtr<KString> string)
|
||||
{
|
||||
FlatPtr string_id = m_strings.size();
|
||||
TRY(m_strings.try_set(move(string)));
|
||||
return string_id;
|
||||
auto it = m_strings.find(string);
|
||||
if (it != m_strings.end()) {
|
||||
return it->value;
|
||||
}
|
||||
|
||||
auto new_index = m_strings.size();
|
||||
TRY(m_strings.try_set(move(string), move(new_index)));
|
||||
return new_index;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue