mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Use a test that makes the extra file read unnecessary
The previous test was: * `has_changes = result != r_data.read(filesize)` This test was validating that `result` is not the same as the contents of the file. The only way for `has_changes` to become true at this point in code would be if `pattern` exists in the file (`nrepl > 0`), and if `pattern == repl`. The new test just checks explicitly for this one condition, eliminating the extra file read.
This commit is contained in:
parent
6d6121a6e5
commit
0835b005b7
1 changed files with 1 additions and 2 deletions
|
@ -1446,7 +1446,7 @@ def replace(path,
|
|||
if nrepl > 0:
|
||||
found = True
|
||||
# Identity check the potential change
|
||||
has_changes = result != r_data.read(filesize)
|
||||
has_changes = True if pattern != repl else has_changes
|
||||
|
||||
if prepend_if_not_found or append_if_not_found:
|
||||
# Search for content, to avoid pre/appending the
|
||||
|
@ -1461,7 +1461,6 @@ def replace(path,
|
|||
# modified
|
||||
if show_changes or append_if_not_found or \
|
||||
prepend_if_not_found:
|
||||
r_data.seek(0)
|
||||
orig_file = r_data.read(filesize).splitlines(True)
|
||||
new_file = result.splitlines(True)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue