[libc-commits] [libc] [libc] Use best-fit binary trie to make malloc logarithmic (PR #106259)

Daniel Thornburgh via libc-commits libc-commits at lists.llvm.org
Thu Oct 10 16:03:40 PDT 2024


================
@@ -0,0 +1,252 @@
+//===-- Interface for freetrie --------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_FREETRIE_H
+#define LLVM_LIBC_SRC___SUPPORT_FREETRIE_H
+
+#include "freelist.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+/// A trie of free lists.
+
+class FreeTrie {
+public:
+  /// A trie node that is also a free list. The subtrie contains a continous
+  /// SizeRange of free lists. The lower and upper subtrie's contain the lower
+  /// and upper half of the subtries range. There is no direct relationship
+  /// between the size of this node's free list and the contents of the lower
+  /// and upper subtries.
+  class Node : public FreeList::Node {
+    /// Return an abitrary leaf in the subtrie.
+    Node &leaf();
----------------
mysterymath wrote:

Good call; there's already a comment in `remove` about why a leaf is selected, and the implementation is quite obvious (and just 2 lines) given that context.

https://github.com/llvm/llvm-project/pull/106259


More information about the libc-commits mailing list