-
Notifications
You must be signed in to change notification settings - Fork 189
refactor: modularize files and refactor existing implementations #438
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
Open
alejandro-vaz
wants to merge
8
commits into
servo:v2
Choose a base branch
from
alejandro-vaz:modularization
base: v2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8378b26
feat: added rustfmt.toml
alejandro-vaz e66df4d
feat: added bytes, serde, std, taggedlen files
alejandro-vaz b27e385
fix: style checked
alejandro-vaz 38ea7ba
feat: added references file
alejandro-vaz 3e02aa8
fix: style
alejandro-vaz 46e847c
feat: more modules
alejandro-vaz ae12395
refactor: conversions file
alejandro-vaz 65cbc1e
fix: made error type public again
alejandro-vaz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| wrap_comments = true | ||
| imports_granularity = "One" | ||
| group_imports = "One" | ||
| format_code_in_doc_comments = true | ||
| match_arm_blocks = false | ||
| blank_lines_lower_bound = 0 | ||
| blank_lines_upper_bound = 0 | ||
| condense_wildcard_suffixes = true | ||
| error_on_unformatted = true | ||
| error_on_line_overflow = true | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| use { | ||
| alloc::alloc::Layout, | ||
| core::{ | ||
| error::Error, | ||
| fmt::{Display, Formatter, Result as Format}, | ||
| }, | ||
| }; | ||
| /// Error type for APIs with fallible heap allocation | ||
| #[derive(Debug)] | ||
| pub enum AllocationError { | ||
| /// Overflow `usize::MAX` or other error during size computation | ||
| CapacityOverflow, | ||
| /// The allocator return an error | ||
| Failure { | ||
| /// The layout that was passed to the allocator | ||
| layout: Layout, | ||
| }, | ||
| } | ||
| impl Display for AllocationError { | ||
| fn fmt(&self, f: &mut Formatter) -> Format { | ||
| write!(f, "Allocation error: {:?}", self) | ||
| } | ||
| } | ||
| impl Error for AllocationError {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| use { | ||
| super::SmallVec, | ||
| bytes::{buf::UninitSlice, BufMut}, | ||
| }; | ||
| unsafe impl<const N: usize> BufMut for SmallVec<u8, N> { | ||
| #[inline] | ||
| fn remaining_mut(&self) -> usize { | ||
| // A vector can never have more than isize::MAX bytes | ||
| isize::MAX as usize - self.len() | ||
| } | ||
| #[inline] | ||
| unsafe fn advance_mut(&mut self, cnt: usize) { | ||
| let len = self.len(); | ||
| let remaining = self.capacity() - len; | ||
| if remaining < cnt { | ||
| panic!("advance out of bounds: the len is {remaining} but advancing by {cnt}"); | ||
| } | ||
| // Addition will not overflow since the sum is at most the capacity. | ||
| self.set_len(len + cnt); | ||
| } | ||
| #[inline] | ||
| fn chunk_mut(&mut self) -> &mut UninitSlice { | ||
| if self.capacity() == self.len() { | ||
| self.reserve(64); // Grow the smallvec | ||
| } | ||
| let cap = self.capacity(); | ||
| let len = self.len(); | ||
| let ptr = self.as_mut_ptr(); | ||
| // SAFETY: Since `ptr` is valid for `cap` bytes, `ptr.add(len)` must be | ||
| // valid for `cap - len` bytes. The subtraction will not underflow since | ||
| // `len <= cap`. | ||
| unsafe { UninitSlice::from_raw_parts_mut(ptr.add(len), cap - len) } | ||
| } | ||
| // Specialize these methods so they can skip checking `remaining_mut` | ||
| // and `advance_mut`. | ||
| #[inline] | ||
| fn put<T: bytes::Buf>(&mut self, mut src: T) | ||
| where | ||
| Self: Sized, | ||
| { | ||
| // In case the src isn't contiguous, reserve upfront. | ||
| self.reserve(src.remaining()); | ||
| while src.has_remaining() { | ||
| let s = src.chunk(); | ||
| let l = s.len(); | ||
| self.extend_from_slice(s); | ||
| src.advance(l); | ||
| } | ||
| } | ||
| #[inline] | ||
| fn put_slice(&mut self, src: &[u8]) { | ||
| self.extend_from_slice(src); | ||
| } | ||
| #[inline] | ||
| fn put_bytes(&mut self, val: u8, cnt: usize) { | ||
| // If the addition overflows, then the `resize` will fail. | ||
| let new_len = self.len().saturating_add(cnt); | ||
| self.resize(new_len, val); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I don't think removing all blank lines improves readability; I think it makes it worse. Also note that
servo/servodoesn't do this (example)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.
fair
then probably 0 for lower bound and 1 for upper I guess. 2+ looks weird to me
did it out of inertia, didn't think much about it, I'll fix it tomorrow
code looks weird though now that you're saying it