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

Memchr in std #30381

Merged
merged 4 commits into from
Dec 19, 2015
Merged

Memchr in std #30381

merged 4 commits into from
Dec 19, 2015

Conversation

fhahn
Copy link
Contributor

@fhahn fhahn commented Dec 14, 2015

This PR adds memchrand memrchr based on @BurntSushi 's rust-memchr crate to libstd (as discussed in #30151).

I've update some places in libstd to use memchr/memrchr, but I am not sure if there are other places where it could be used as well.

ref #30076

@@ -0,0 +1,339 @@
/* Initial implementation taken from Andrew Gallant's rust-memchr
Copy link
Member

Choose a reason for hiding this comment

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

Needs a real copyright header, see other files.

If you put in burntsushi's name, I want to be credited too -- the pure rust memchr impls are mine. bluss is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added the rust copyright header, as well as rust-memchrs license header.

@bluss I'd be glad to put your name in as well, what should I put in? It's not in the rust-memchr copyright notice.

@bluss
Copy link
Member

bluss commented Dec 15, 2015

I think this is exciting, should be a good perf boost to stdout when writing binary data.

@bluss bluss added the relnotes Marks issues that should be documented in the release notes of the next release. label Dec 15, 2015
@bluss
Copy link
Member

bluss commented Dec 15, 2015

You can write in (C) bluss or another way to indicate authorship. We should resolve the license question and skip the separate license notice I think.

@bluss
Copy link
Member

bluss commented Dec 15, 2015

@nicokoch Do you agree with dual-licensing your contributions to rust-memchr under MIT and Apache 2.0 so that it can be included in rust?

@BurntSushi Do you agree with dual-licensing your contributions to rust-memchr under MIT and Apache 2.0 so that it can be included in rust?

I myself agree with dual licensing my contributions to rust-memchr 😄.

Those are all three authors according to the git history.

@nicokoch
Copy link
Contributor

Exciting, my first mini contribution to rust!

No problem on my end, go ahead and include it.

@bluss
Copy link
Member

bluss commented Dec 15, 2015

☑️ great, then the little licensing question should be almost cleared, I have no doubt @BurntSushi will be on board as soon as he sees it.

@BurntSushi
Copy link
Member

Yes, i agree. Also, to be clear, the memchr crate is far more the work of @bluss than myself! Thank you @bluss! (And thank you @fhahn for the PR!)

@bluss
Copy link
Member

bluss commented Dec 15, 2015

☑️ relicensing done, well done team ❤️

@fhahn fhahn force-pushed the memchr-in-std branch 3 times, most recently from e49137c to 40900af Compare December 15, 2015 10:47
@fhahn
Copy link
Contributor Author

fhahn commented Dec 15, 2015

I've update the license stuff, memchr.rs now includes the Rust license header on top and a comment below which indicates the file initially comes from rust-memchr with an copyright attribution for the three contributers.

// Copyright 2015 Andrew Gallant, bluss and Nicolas Koch


extern crate libc;
Copy link
Member

Choose a reason for hiding this comment

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

This is not needed (libc is already imported in lib.rs)

// libc memchr
#[cfg(any(not(target_os = "windows"),
not(any(target_pointer_width = "32",
target_pointer_width = "64"))))]
Copy link
Member

Choose a reason for hiding this comment

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

I think it's probably safe to say that if we're porting to a platform which doesn't have 32 or 64-bit pointers this function will be the least of our worries. For now could these clauses in the cfg annotations just be removed?

Copy link
Member

Choose a reason for hiding this comment

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

(ping on removing these cfgs)

@fhahn
Copy link
Contributor Author

fhahn commented Dec 16, 2015

I've update the commit. I also added a PR to libc that adds memrchr. But this means we must update the libc submodule in the repo, right?

In the libc PR I also add memrchr bindings for Free, Net and OpenBSD, because they are provided there as well. They do not seem to ship handwritten assembler version (as GUN libc does), which means they probably won't beat the Rust implementation by a large margin.

@alexcrichton
Copy link
Member

Also yeah updating the submodule is fine, should be fine to do as soon as the libc PR lands.

@fhahn
Copy link
Contributor Author

fhahn commented Dec 17, 2015

I've updated the submodule and the new libc binding of memrchr is used.

@alexcrichton
Copy link
Member

@bors: r+ d21888d650f9a72e862ec469d755674938a6b7a9

Thanks @fhahn!

@alexcrichton alexcrichton self-assigned this Dec 18, 2015
@fhahn
Copy link
Contributor Author

fhahn commented Dec 18, 2015

@Manishearth I've moved the libc import to the functions that use it

bors added a commit that referenced this pull request Dec 18, 2015
@bluss
Copy link
Member

bluss commented Dec 18, 2015

From travis log, the doc examples need updating (or ignoring)


---- memchr::memchr_0 stdout ----
    <anon>:4:9: 4:15 error: unresolved import `memchr::memchr`. Maybe a missing `extern crate memchr`? [E0432]
<anon>:4     use memchr::memchr;
                 ^~~~~~
error: aborting due to previous error
thread 'memchr::memchr_0' panicked at 'Box<Any>', src/libsyntax/diagnostic.rs:240

---- memchr::memrchr_0 stdout ----
    <anon>:4:9: 4:15 error: unresolved import `memchr::memrchr`. Maybe a missing `extern crate memchr`? [E0432]
<anon>:4     use memchr::memrchr;
                 ^~~~~~
error: aborting due to previous error
thread 'memchr::memrchr_0' panicked at 'Box<Any>', src/libsyntax/diagnostic.rs:240


failures:
    memchr::memchr_0
    memchr::memrchr_0

@fhahn
Copy link
Contributor Author

fhahn commented Dec 18, 2015

I've added ignore to the doc tests

@alexcrichton
Copy link
Member

@bors: r+ a206e55

@bluss
Copy link
Member

bluss commented Dec 18, 2015

Thanks for working on this!

@bors
Copy link
Contributor

bors commented Dec 19, 2015

⌛ Testing commit a206e55 with merge 8ad12c3...

bors added a commit that referenced this pull request Dec 19, 2015
This PR adds `memchr`and `memrchr` based on @BurntSushi 's rust-memchr crate to libstd (as discussed in #30151).

I've update some places in libstd to use memchr/memrchr, but I am not sure if there are other places where it could be used as well.

ref #30076
@SimonSapin
Copy link
Contributor

These new functions are private to std, right?

If they are to become public, I’d prefer to have a more descriptive name, similar to how copy_nonoverlapping is not named memcpy.

@bluss
Copy link
Member

bluss commented Dec 22, 2015

Yep they are an implementation detail.

The relnotes-worthy thing is the performance improvements. We'll probably expand the use of these functions soon.

@bluss
Copy link
Member

bluss commented Dec 22, 2015

relnotes related: Improve throughput for LineWriter (and thus default stdout).

@fhahn fhahn deleted the memchr-in-std branch December 22, 2015 23:31
bors added a commit that referenced this pull request Jan 21, 2016
Use the fallback impl for memrchr on non-linux

The memrchr code was never used(!). This brings the memrchr improvements to
non-linux platforms (LineWriter / buffered stdout benefits).

Previous PR #30381
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes Marks issues that should be documented in the release notes of the next release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants