-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[stdlib] Implement Writer for List[Byte] #3758
base: nightly
Are you sure you want to change the base?
Conversation
Signed-off-by: Lukas Hermann <[email protected]>
@@ -592,6 +621,18 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( | |||
# list. | |||
self.size = final_size | |||
|
|||
fn extend(inout self, other: Span[T]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion Add some unit tests for this new public API method.
assert_equal(l[0], ord("a")) | ||
assert_equal(l[1], ord("b")) | ||
assert_equal(l[2], ord("c")) | ||
var l2 = List[Byte]() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question Can you explain this part of the test? I'm not sure I follow.
null terminated. | ||
""" | ||
constrained[_type_is_eq[T, Byte]()]() | ||
self.extend(rebind[Span[T, bytes.origin]](bytes)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the extend method has a lot of overhead if you know it's a DType
. Until we land #3577 this logic will have to stay here
self.extend(rebind[Span[T, bytes.origin]](bytes)) | |
self.reserve(len(self) + len(bytes)) | |
memcpy( | |
self.unsafe_ptr() + len(self), | |
bytes.unsafe_ptr().bitcast[T](), | |
len(bytes), | |
) |
I'll sync this internally for you so you can iterate on it in-tree. |
!sync |
This PR adds the
Writer
trait toList
with a constraint that theT
isByte
.