[PATCH] D65087: [yaml2elf] - Treat the SHT_NULL section as kind of regular section.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 22 07:35:02 PDT 2019


grimar marked an inline comment as done.
grimar added inline comments.


================
Comment at: tools/yaml2obj/yaml2elf.cpp:328
 
-  for (size_t I = 1; I < Doc.Sections.size() + 1; ++I) {
+  for (size_t I = 1; I < Doc.Sections.size(); ++I) {
     Elf_Shdr &SHeader = SHeaders[I];
----------------
MaskRay wrote:
> You can circumvent the violation of https://llvm.org/docs/CodingStandards.html#don-t-evaluate-end-every-time-through-a-loop by assigning Doc.Sections.size() to a variable above (it is also used above)
`Doc.Sections` is a vector. `size()` has a trivial implementation, for me it is:

```
	_NODISCARD size_type size() const noexcept
		{	// return length of sequence
		return (static_cast<size_type>(this->_Mylast() - this->_Myfirst()));
		}
```

I do not think it is very common to introduce a new variable to store `size()` value
returned by a vector in LLVM (well, sometimes we use `(for I = 0, E =...`, but not always).

And it doesn't seem worth to do. I think that coding standart assumes that re-evaluting might
be expensive. But this is not the case.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65087/new/

https://reviews.llvm.org/D65087





More information about the llvm-commits mailing list