-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
add Show
impl for Tree{Map,Set} and cleanup
#14447
Conversation
res.push_char(char::from_u32(n as u32).unwrap()); | ||
} | ||
_ => return self.error(InvalidEscape), | ||
>>>>>>> Add a streaming parser to serialize::json.*/ |
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.
!!!
Should that commented block be deleted or uncommented? |
Is there an actual need for |
/// Reserve space for an additional `n` elements in the hash table. | ||
pub fn reserve_additional(&mut self, extra: uint) { | ||
let len = self.len(); | ||
if self.minimum_capacity - len < extra { |
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.
minimum_capacity
is not guaranteed to be >= len
. It's a minimum and is only modified by an explicit call to reserve()
or, apparently, to clear()
.
Thinking about it some more, it seems to me that I'm assuming here that |
@sfackler: parsing of escaped characters was replaced with https://github.com/mozilla/rust/blob/master/src/libserialize/json.rs#L1411 in #13469, which fixed decoding non-BMP hex escapes, so I think it should be okay to remove this dead code. It just got missed in a review. |
@kballard: Yep, I added it because I wanted to add a bunch of items to an already existing |
@erickt
|
Basically, Given the difference of |
@kballard: I still don't see the issue here :) In my opinion, the |
I think Given that, I would feel more comfortable removing |
Show
impl for Tree{Map,Set}, add .reserve_additional, and cleanupShow
impl for Tree{Map,Set} and cleanup
@kballard: I removed the |
@@ -67,6 +69,19 @@ impl<K: Ord + TotalOrd, V: Ord> Ord for TreeMap<K, V> { | |||
fn lt(&self, other: &TreeMap<K, V>) -> bool { lt(self, other) } | |||
} | |||
|
|||
impl<K: Eq + TotalOrd + Show, V: Show> Show for TreeMap<K, V> { |
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.
Eq
is an unnecessary bound here. TreeMap
only requires TotalOrd
(which as it happens includes Eq
via TotalEq
).
I'm not convinced that we need extra bounds (like TotalOrd
) at all on unrelated traits, since you can't even construct a TreeMap
without TotalOrd
, but precedent so far is to use the "required" bounds on all traits. So <K: TotalOrd + Show, V: Show>
should be correct.
@@ -547,6 +562,19 @@ impl<T: Ord + TotalOrd> Ord for TreeSet<T> { | |||
fn lt(&self, other: &TreeSet<T>) -> bool { self.map < other.map } | |||
} | |||
|
|||
impl<T: Eq + TotalOrd + Show> Show for TreeSet<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.
Same thing about the Eq
bound here.
r=me with comments |
@kballard: I addressed your comments in the latest version. |
This is a hodge podge of a couple small cleanup commits. It implements `Show` for `TreeMap` and `TreeSet`, and some removal of commented out code.
This is a hodge podge of a couple small cleanup commits. It implements
Show
forTreeMap
andTreeSet
, and some removal of commented out code.