Pārlūkot izejas kodu

Kernel/ProcFS: Avoid two unnecessary number-to-string conversions

We don't need to create a new string from a number in order to compare
an existing string to that number. Converting the existing string to a
number is much cheaper, since it does not require any heap allocations.

Ran into this while profiling "find /" :^)
Andreas Kling 3 gadi atpakaļ
vecāks
revīzija
a412fd2ed8
1 mainītis faili ar 2 papildinājumiem un 2 dzēšanām
  1. 2 2
      Kernel/ProcessSpecificExposed.cpp

+ 2 - 2
Kernel/ProcessSpecificExposed.cpp

@@ -61,7 +61,7 @@ KResultOr<NonnullRefPtr<Inode>> Process::lookup_stacks_directory(const ProcFS& p
     for_each_thread([&](const Thread& thread) {
         int tid = thread.tid().value();
         VERIFY(!(tid < 0));
-        if (name == String::number(tid)) {
+        if (name.to_int() == tid) {
             auto maybe_inode = ProcFSProcessPropertyInode::try_create_for_thread_stack(procfs, thread.tid(), pid());
             if (maybe_inode.is_error()) {
                 thread_stack_inode = maybe_inode.error();
@@ -114,7 +114,7 @@ KResultOr<NonnullRefPtr<Inode>> Process::lookup_file_descriptions_directory(cons
             count++;
             return;
         }
-        if (name == String::number(count)) {
+        if (name.to_uint() == count) {
             auto maybe_inode = ProcFSProcessPropertyInode::try_create_for_file_description_link(procfs, static_cast<unsigned>(count), pid());
             if (maybe_inode.is_error()) {
                 file_description_link = maybe_inode.error();