[libcxx-commits] [libcxx] Change 'grow_by' to use precise size for the first SSO --> long allocation (PR #69967)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Nov 8 16:39:10 PST 2023


================
@@ -40,6 +41,25 @@ int main(int, char**) {
   } else {
     assert(test_string.capacity() == expected_align8_size + 8);
   }
+}
+
+void test_resize_from_small_size() {
+  // Test that we don't waste additional bytes when growing from the SSO
+  // to a specific size. The size of the SSO is an implementation detail
+  // and shouldn't be taken into account when deciding on the next size.
+  {
+    const std::size_t sso_capacity = std::string().capacity();
+    const std::string input(sso_capacity, 'a');
+    std::string s;
+    s = input.c_str();
+    std::printf("Have Capacity = %zu and size = %zu\n", s.capacity(), s.size());
----------------
ldionne wrote:

Did you mean to keep that printf around? Generally we don't add those in our tests because it makes it harder for e.g. embedded platforms. I don't think that's something we catch in our CI but we should still be cognizant of that, for example I know for a fact it'll break some downstream configurations.

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


More information about the libcxx-commits mailing list