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

Cleaned up str module a bit #9392

Merged
merged 1 commit into from
Sep 26, 2013
Merged

Cleaned up str module a bit #9392

merged 1 commit into from
Sep 26, 2013

Conversation

Kimundi
Copy link
Member

@Kimundi Kimundi commented Sep 21, 2013

Moved StrSlice doc comments from impl to trait.
Moved OwnedStr doc comments from impl to trait.
Normalized a few StrSlice method names from FOO_reverse, FOO_rev and rFOO to FOO_rev.
Added a few #[inline] hints.

The doc comment changes make the source a bit harder to read, as documentation and implementation no longer live right next to each other. But this way they at least appear in the docs.

@@ -268,7 +271,7 @@ impl<'self, S: Str> StrVector for &'self [S] {
result
}

/// Concatenate a vector of strings, placing a given separator between each.
#[inline]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these really need to get tagged as inline? It seems like performance-critical code wouldn't be calling these functions anyway, and they're pretty large to get inlined.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was my understanding that an #[inline] hint merely allows llvm to cross-crate inline a function if it deems it useful.
As far as I know, this doesn't actually force an inline? Or is the growing size of the metadata section an problem?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's both growing the size of the metadata and slowing compilation of modules linking to libstd in the sense that they have more code to process with LLVM. There's really no need for these to get inlined across crates because they're fairly large chunks of code and probably wouldn't get inlined in the first place anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use #[inline], it no longer outputs a symbol in the library and forces it to be recompiled in each crate. It also puts a very strong inline hint on the function, overriding the regular cost heuristic. If you made a very bad choice, LLVM can choose to not inline it, but it will still have a pointless duplicate version of it per-crate.

@alexcrichton
Copy link
Member

All of the documentation movements look good to me, although I'm less certain about the renamings. I don't feel too strong either way, but there's should probably be more agreement.

@Kimundi
Copy link
Member Author

Kimundi commented Sep 22, 2013

I removed most of the new the #[inline] attributes again. I kept a few where I though they would be useful, though.

@alexcrichton
Copy link
Member

Cool, thanks! Let's get a few more opinions about the renamings before merging though.

@huonw
Copy link
Member

huonw commented Sep 23, 2013

FWIW, a pile of languages use r to mean reverse: Haskell (Data.Sequence.findIndiciesR), Python (str.rfind), Ruby (Array#rindex), C++ (vector::rbegin), PHP (strrpos). In fact, I can't think of any that use rev/reverse off the top of my head; e.g. Javascript/Java/C# use lastIndexOf.

I'm not particularly fussed either way. Some other points: riter looks slightly silly (for a reverse iterator), rev_* is slightly more to type.

@emberian
Copy link
Member

@Kimundi can you split out the renaming from this patch, since it's otherwise-good? Additionally, rebasing it on top of #9475 would be nice.

@Kimundi
Copy link
Member Author

Kimundi commented Sep 25, 2013

@cmr I split out the renaming, and rebased on #9475. Gonna wait till that lands and rebase on master though.

@Kimundi
Copy link
Member Author

Kimundi commented Sep 26, 2013

@cmr Rebased on master, all set for a review. :)

@@ -990,9 +991,14 @@ pub fn utf8_char_width(b: u8) -> uint {
return UTF8_CHAR_WIDTH[b] as uint;
}

#[allow(missing_doc)]
/// Struct that contains a `char` and an next byte index.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"the index of first byte of the next char in a string."?

Moved OwnedStr doc comments from impl to trait.
Added a few #[inline] hints.

The doc comment changes make the source a bit harder to read, as
documentation and implementation no longer live right next to each
other. But this way they at least appear in the docs.
bors added a commit that referenced this pull request Sep 26, 2013
Moved `StrSlice` doc comments from impl to trait.
Moved `OwnedStr` doc comments from impl to trait.
Normalized a few `StrSlice` method names from `FOO_reverse`, `FOO_rev` and `rFOO` to `FOO_rev`.
Added a few `#[inline]` hints.

The doc comment changes make the source a bit harder to read, as documentation and implementation no longer live right next to each other. But this way they at least appear in the docs.
@bors bors closed this Sep 26, 2013
@bors bors merged commit e94b3fa into rust-lang:master Sep 26, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants