瀏覽代碼

Kernel/DevPtsFS: Avoid String allocation during directory traversal

Use a StringBuilder to generate a temporary string buffer with the
slave PTY names. (This works because StringBuilder has 128 bytes of
inline stack capacity before it does any heap allocations.)
Andreas Kling 3 年之前
父節點
當前提交
3a2d888913
共有 1 個文件被更改,包括 3 次插入3 次删除
  1. 3 3
      Kernel/FileSystem/DevPtsFS.cpp

+ 3 - 3
Kernel/FileSystem/DevPtsFS.cpp

@@ -118,9 +118,9 @@ KResult DevPtsFSInode::traverse_as_directory(Function<bool(FileSystem::Directory
 
     SlavePTY::all_instances().with([&](auto& list) {
         for (SlavePTY& slave_pty : list) {
-            String name = String::number(slave_pty.index());
-            InodeIdentifier identifier = { fsid(), pty_index_to_inode_index(slave_pty.index()) };
-            callback({ name, identifier, 0 });
+            StringBuilder builder;
+            builder.appendff("{}", slave_pty.index());
+            callback({ builder.string_view(), { fsid(), pty_index_to_inode_index(slave_pty.index()) }, 0 });
         }
     });