Skip to content
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

Open
wants to merge 1 commit into
base: nightly
Choose a base branch
from

Conversation

lsh
Copy link
Contributor

@lsh lsh commented Nov 8, 2024

This PR adds the Writer trait to List with a constraint that the T is Byte.

Signed-off-by: Lukas Hermann <[email protected]>
@lsh lsh requested a review from a team as a code owner November 8, 2024 00:04
@lsh lsh changed the title implement Writer for List[Byte] [stdlib] Implement Writer for List[Byte] Nov 8, 2024
@martinvuyk
Copy link
Contributor

FYI I opened PR #3745 and then closed it in favor of #3747. Leave comments on the proposal if you have any :)

@@ -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]):
Copy link
Collaborator

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]()
Copy link
Collaborator

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.

@JoeLoser JoeLoser self-assigned this Nov 10, 2024
null terminated.
"""
constrained[_type_is_eq[T, Byte]()]()
self.extend(rebind[Span[T, bytes.origin]](bytes))
Copy link
Contributor

@martinvuyk martinvuyk Nov 10, 2024

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

Suggested change
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),
)

@JoeLoser
Copy link
Collaborator

I'll sync this internally for you so you can iterate on it in-tree.

@JoeLoser
Copy link
Collaborator

!sync

@modularbot modularbot added the imported-internally Signals that a given pull request has been imported internally. label Nov 14, 2024
@JoeLoser JoeLoser added the waiting for response Needs action/response from contributor before a PR can proceed label Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
imported-internally Signals that a given pull request has been imported internally. waiting for response Needs action/response from contributor before a PR can proceed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants