diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2017-06-25 10:49:03 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2017-06-25 11:02:15 -0700 |
commit | dc5f112c3ea8aff1a389513fa6c33d88fab07420 (patch) | |
tree | 5e887029c973d8a5b292fd9993c5ad81cf8c4c61 /edit | |
parent | d2f0704962eb0e43f3db8b461dd6d48ee9297f73 (diff) | |
download | mu-dc5f112c3ea8aff1a389513fa6c33d88fab07420.tar.gz |
3958
Improvement on fix 3957: rather than put a band-aid over a slow operation, eliminate the slowdown entirely. In this case it turns out we're unnecessarily saving files to disk when they could never be modified. Are we doing this on F4 as well?!
Diffstat (limited to 'edit')
-rw-r--r-- | edit/005-sandbox.mu | 14 | ||||
-rw-r--r-- | edit/009-sandbox-test.mu | 18 |
2 files changed, 19 insertions, 13 deletions
diff --git a/edit/005-sandbox.mu b/edit/005-sandbox.mu index fc618b3b..8fd88cba 100644 --- a/edit/005-sandbox.mu +++ b/edit/005-sandbox.mu @@ -233,16 +233,22 @@ def save-sandboxes env:&:environment, resources:&:resources -> resources:&:resou idx:num <- copy 0 { break-unless curr - data:text <- get *curr, data:offset - filename:text <- append [lesson/], idx - resources <- dump resources, filename, data - <end-save-sandbox> + resources <- save-sandbox resources, curr, idx idx <- add idx, 1 curr <- get *curr, next-sandbox:offset loop } ] +def save-sandbox resources:&:resources, sandbox:&:sandbox, sandbox-index:num -> resources:&:resources [ + local-scope + load-ingredients + data:text <- get *sandbox, data:offset + filename:text <- append [lesson/], sandbox-index + resources <- dump resources, filename, data + <end-save-sandbox> +] + def! render-sandbox-side screen:&:screen, env:&:environment, render-editor:render-recipe -> screen:&:screen, env:&:environment [ local-scope load-ingredients diff --git a/edit/009-sandbox-test.mu b/edit/009-sandbox-test.mu index f095579d..5966617c 100644 --- a/edit/009-sandbox-test.mu +++ b/edit/009-sandbox-test.mu @@ -95,7 +95,7 @@ container sandbox [ # include expected response when saving or restoring a sandbox before <end-save-sandbox> [ { - expected-response:text <- get *curr, expected-response:offset + expected-response:text <- get *sandbox, expected-response:offset break-unless expected-response filename <- append filename, [.out] resources <- dump resources, filename, expected-response @@ -126,20 +126,18 @@ after <global-touch> [ below-sandbox-editor?:bool <- greater-or-equal click-row, first-sandbox-begins break-unless below-sandbox-editor? # identify the sandbox whose output is being clicked on - sandbox:&:sandbox <- find-click-in-sandbox-output env, click-row + sandbox:&:sandbox, sandbox-index:num <- find-click-in-sandbox-output env, click-row break-unless sandbox - screen <- update-status screen, [updating... ], 245/grey # toggle its expected-response, and save session sandbox <- toggle-expected-response sandbox - save-sandboxes env, resources + save-sandbox resources, sandbox, sandbox-index screen <- render-sandbox-side screen, env, render - screen <- update-status screen, [ ], 245/grey screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env loop +next-event } ] -def find-click-in-sandbox-output env:&:environment, click-row:num -> sandbox:&:sandbox [ +def find-click-in-sandbox-output env:&:environment, click-row:num -> sandbox:&:sandbox, sandbox-index:num [ local-scope load-ingredients # assert click-row >= sandbox.starting-row-on-screen @@ -148,6 +146,7 @@ def find-click-in-sandbox-output env:&:environment, click-row:num -> sandbox:&:s clicked-on-sandboxes?:bool <- greater-or-equal click-row, start assert clicked-on-sandboxes?, [extract-sandbox called on click to sandbox editor] # while click-row < sandbox.next-sandbox.starting-row-on-screen + sandbox-index <- copy 0 { next-sandbox:&:sandbox <- get *sandbox, next-sandbox:offset break-unless next-sandbox @@ -155,14 +154,15 @@ def find-click-in-sandbox-output env:&:environment, click-row:num -> sandbox:&:s found?:bool <- lesser-than click-row, next-start break-if found? sandbox <- copy next-sandbox + sandbox-index <- add sandbox-index, 1 loop } # return sandbox if click is in its output region response-starting-row:num <- get *sandbox, response-starting-row-on-screen:offset - return-unless response-starting-row, 0/no-click-in-sandbox-output + return-unless response-starting-row, 0/no-click-in-sandbox-output, 0/sandbox-index click-in-response?:bool <- greater-or-equal click-row, response-starting-row - return-unless click-in-response?, 0/no-click-in-sandbox-output - return sandbox + return-unless click-in-response?, 0/no-click-in-sandbox-output, 0/sandbox-index + return sandbox, sandbox-index ] def toggle-expected-response sandbox:&:sandbox -> sandbox:&:sandbox [ |