eliminate string clone by using std::mem::take in json editor tutorial - #1010
eliminate string clone by using std::mem::take in json editor tutorial#1010AdamSteinberg1 wants to merge 2 commits into
Conversation
|
The tutorials are meant to be beginner friendly so I'm not sure if With that being said, I'm not against this change. It's a JSON editor tutorial which can be considered as intermediate level. |
Group the in-progress key/value pair with the active editing field so saving can move the draft into the stored pairs without cloning. This keeps the tutorial state model closer to the UI workflow and removes invalid combinations of editing state.
|
I pushed an update directly to this PR branch. I think this shape is better than only replacing clone-and-clear with |
|
Yeah, those CI jobs are stuck for a while now. We can try deleting the cache manually and rerunning them probably |
|
didn't seem to help - maybe something in the pnpm formatting broke. |
|
will take another look later. |

I was going through the json editor tutorial and noticed on this page that there was an unnecessary clone. In the code we clone two Strings to insert them into a HashMap. Then we clear the contents of the Strings setting them to
String::new(). It's unnecessary to clone when the next thing we do is delete.std::mem::takeis a better approach.