Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@pull
Copy link

@pull pull bot commented Nov 4, 2025

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.4)

Can you help keep this open source service alive? 💖 Please sponsor : )

Fixes #

### Context
I was working on something else entirely and saw some easy improvements
to make in `WriteLinesToFile`.

### Changes Made
1. `File.ItemSpec` is being accessed 14 times. I think the
implementation will [make a new
string](https://github.com/jeffkl/msbuild/blob/f4e7bc9c01e75873d00a36b6f6a9e3dabb771c21/src/Build/Instance/ProjectItemInstance.cs?plain=1#L927C1-L928C1)
each time.
2. It has two code paths, overwrite vs not and both code paths were
creating the directory
3. The contents of the file to write are stored in a `StringBuilder`
with no initial capacity. I took a wild guess and set to `lines * 64`
4. If no lines are specified, a `StringBuilder` is no longer created and
instead it uses `string.Empty`
5. Since the contents are now stored in a string on all code paths, the
comparison of the current vs new is simplified since `string.Equals()`
will check the length
6. Reduced nesting by inverting the `if (File != null)` statement

### Testing
From what I can tell, the existing tests are good.

### Notes
@pull pull bot locked and limited conversation to collaborators Nov 4, 2025
@pull pull bot added the ⤵️ pull label Nov 4, 2025
@pull pull bot merged commit 27c7c81 into thompson-tomo:main Nov 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant