[llvm-commits] [llvm] r146599 - in /llvm/trunk: lib/MC/MCParser/AsmParser.cpp test/MC/AsmParser/directive_incbin.s

Chris Lattner clattner at apple.com
Wed Dec 14 15:47:55 PST 2011


On Dec 14, 2011, at 2:34 PM, Kevin Enderby wrote:

> Author: enderby
> Date: Wed Dec 14 16:34:45 2011
> New Revision: 146599
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=146599&view=rev
> Log:
> Improve the implementation of .incbin directive by replacing a loop by using
> getStreamer().EmitBytes.  Suggestion by Benjamin Kramer!

One more tweak:

> +  // Pick up the bytes from the file and emit them.
>   const char *BufferStart = SrcMgr.getMemoryBuffer(NewBuf)->getBufferStart();
> +  size_t BufferSize = SrcMgr.getMemoryBuffer(NewBuf)->getBufferSize();
> +  std::string Data(BufferStart, BufferSize);
> +  getStreamer().EmitBytes(Data, DEFAULT_ADDRSPACE);

This makes a copy of the file into the std::string.  You can just use:

getStreamer().EmitBytes(SrcMgr.getMemoryBuffer(NewBuf)->getBuffer(), DEFAULT_ADDRSPACE);

which avoids the copy by passing with a StringRef (just a pointer into the  existing buffer).

If we're going to have incbin, it might as well be fast ;-)

-Chris



More information about the llvm-commits mailing list