[llvm] r216360 - Support/Path: remove raw delete

David Blaikie dblaikie at gmail.com
Mon Aug 25 09:22:05 PDT 2014


On Sun, Aug 24, 2014 at 5:58 PM, Dylan Noblesmith <nobled at dreamwidth.org> wrote:
> Author: nobled
> Date: Sun Aug 24 19:58:13 2014
> New Revision: 216360
>
> URL: http://llvm.org/viewvc/llvm-project?rev=216360&view=rev
> Log:
> Support/Path: remove raw delete
>
> Modified:
>     llvm/trunk/lib/Support/Path.cpp
>
> Modified: llvm/trunk/lib/Support/Path.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Path.cpp?rev=216360&r1=216359&r2=216360&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Support/Path.cpp (original)
> +++ llvm/trunk/lib/Support/Path.cpp Sun Aug 24 19:58:13 2014
> @@ -881,7 +881,8 @@ std::error_code copy_file(const Twine &F
>    }
>
>    const size_t BufSize = 4096;
> -  char *Buf = new char[BufSize];
> +  std::vector<char> Buffer(BufSize);
> +  char *Buf = Buffer.data();

I'd skip the intermediate variable and just pass "Buffer.data()" in
the two callsites. It avoids an extra layer of indirection a developer
would have to look through while following this code.

(but opinions may differ here)

>    int BytesRead = 0, BytesWritten = 0;
>    for (;;) {
>      BytesRead = read(ReadFD, Buf, BufSize);
> @@ -898,7 +899,6 @@ std::error_code copy_file(const Twine &F
>    }
>    close(ReadFD);
>    close(WriteFD);
> -  delete[] Buf;
>
>    if (BytesRead < 0 || BytesWritten < 0)
>      return std::error_code(errno, std::generic_category());
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list