Coder Social home page Coder Social logo

Comments (4)

andrewhickman avatar andrewhickman commented on June 15, 2024

Thanks for the suggestion! I suspect the addition of the Into<PathBuf> bound on everything means we can't be as good as the standard library on this (since we typically only want to call .into() in the error path), but there are probably some places we can improve.

from fs-err.

matklad avatar matklad commented on June 15, 2024

I don't quite see why Into<PathBuf> is required though? I would expect that monomorphic private functions would just take &Path as an argument, and call .to_path_buf() on the error path. I don't think this meaningfully changes the allocations -- if the caller has only &Path, then the behavior is the same. If the caller has a PathBuf and is ready to sacrifice it to call an fs method, then, yeah, we do an extra allocation on the error path, but:

  • this is a cold path
  • given that we require an owned path in this case, this amortizises to the same number of allocations. Ie, you can't construct a loop where the number of allocations goes from O(1) to O(N)

from fs-err.

andrewhickman avatar andrewhickman commented on June 15, 2024

Good points. I believe constructing a custom io::Error already does two allocations so cloning the path as well is probably OK.

from fs-err.

Emerentius avatar Emerentius commented on June 15, 2024

The change is straightforward except for File constructors and the three functions which construct a File internally (see #31). Those need a PathBuf even on the hot path. Is the performance hit of always cloning big enough that it should be avoided?

from fs-err.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.