diff options
author | Andreas Kling <kling@serenityos.org> | 2021-08-16 22:18:18 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-17 01:21:47 +0200 |
commit | 3a2d8889131b15bdc23721c91fb46d50db0a1aae (patch) | |
tree | dc6dd3dfd2a8e7d8fca781ad55ec4b2199ba82e9 | |
parent | 0de8c95d49e9c5042c4e4581a2483266586064e9 (diff) | |
download | serenity-3a2d8889131b15bdc23721c91fb46d50db0a1aae.zip |
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.)
-rw-r--r-- | Kernel/FileSystem/DevPtsFS.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/Kernel/FileSystem/DevPtsFS.cpp b/Kernel/FileSystem/DevPtsFS.cpp index 136a39afa2..07f56d2e3f 100644 --- a/Kernel/FileSystem/DevPtsFS.cpp +++ b/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 }); } }); |