Skip to content

Commit

Permalink
inline string literal handling directly
Browse files Browse the repository at this point in the history
  • Loading branch information
SchrodingerZhu committed Dec 14, 2024
1 parent fd79e84 commit 6421f9a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 51 deletions.
39 changes: 33 additions & 6 deletions src/snmalloc/ds_core/helpers.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include "bits.h"
#include "string_view.h"

#include <array>
#include <atomic>
Expand Down Expand Up @@ -272,11 +271,12 @@ namespace snmalloc
/**
* Append a string to the buffer.
*/
void append(StringView s)
template<size_t N>
void append(const char (&s)[N])
{
for (auto c : s)
for (size_t i = 0; i < N - 1; i++)
{
append_char(c);
append_char(s[i]);
}
}

Expand Down Expand Up @@ -305,14 +305,41 @@ namespace snmalloc
#endif

/**
* Append a raw pointer to the buffer as a hex string.
* Append a raw pointer or to the buffer as a hex string.
*/
void append(void* ptr)
void append_raw_ptr(const void* ptr)
{
append(static_cast<unsigned long long>(reinterpret_cast<uintptr_t>(ptr)));
// TODO: CHERI bits.
}

/**
* Append a pointer.
*/
template<class T>
void append(const T* ptr)
{
if constexpr (std::is_same_v<T, char>)
{
while (char data = *ptr++)
{
append_char(data);
}
}
else
{
append_raw_ptr(ptr);
}
}

/**
* Append a null pointer.
*/
void append(std::nullptr_t ptr)
{
append_raw_ptr(ptr);
}

/**
* Append a signed integer to the buffer, as a decimal string.
*/
Expand Down
45 changes: 0 additions & 45 deletions src/snmalloc/ds_core/string_view.h

This file was deleted.

0 comments on commit 6421f9a

Please sign in to comment.