summaryrefslogtreecommitdiff
path: root/Shortening the lifetime of borrowed variables before mutating it.md
diff options
context:
space:
mode:
authorJasper Ras <jras@hostnet.nl>2025-08-08 22:44:15 +0200
committerJasper Ras <jras@hostnet.nl>2025-08-08 22:44:15 +0200
commit22675cd8dc75d8b8d4b0f818f5b093efbc364802 (patch)
tree90156d37dccf13f012d535e7d92273259e3d5c17 /Shortening the lifetime of borrowed variables before mutating it.md
parent295b343aecf330e830d79f06e0efc511e7d76da1 (diff)
vault backup: 2025-08-08 22:44:15HEADmain
Diffstat (limited to 'Shortening the lifetime of borrowed variables before mutating it.md')
-rw-r--r--Shortening the lifetime of borrowed variables before mutating it.md9
1 files changed, 9 insertions, 0 deletions
diff --git a/Shortening the lifetime of borrowed variables before mutating it.md b/Shortening the lifetime of borrowed variables before mutating it.md
new file mode 100644
index 0000000..d17506f
--- /dev/null
+++ b/Shortening the lifetime of borrowed variables before mutating it.md
@@ -0,0 +1,9 @@
+[[Creating a reference to a variable is called borrowing]]
+
+---
+
+If a function modifies a borrowed variable, we can try to find a way to shorten the lifetime of the borrow.
+
+One way would be to clone the value into a new variable and mutate that, but it can be expensive.
+
+Another way could be to use some property of the variable instead of the variable itself, ie the length of a string. \ No newline at end of file