diff options
author | Devine Lu Linvega <[email protected]> | 2018-11-17 10:58:19 +1200 |
---|---|---|
committer | Devine Lu Linvega <[email protected]> | 2018-11-17 10:58:19 +1200 |
commit | 68fb2d81a53b1d770a6ac455d30058075883ce71 (patch) | |
tree | 58a835bac2dc1831c81699931b4c542f09ba1345 | |
parent | dd50a142940bc0feff3d9a0cc8ed3572b9d9fc12 (diff) | |
download | Orca-68fb2d81a53b1d770a6ac455d30058075883ce71.tar.gz Orca-68fb2d81a53b1d770a6ac455d30058075883ce71.zip |
Minor optimisations
-rw-r--r-- | desktop/core/lib/_base.js | 4 | ||||
-rw-r--r-- | desktop/core/lib/_midi.js | 6 | ||||
-rw-r--r-- | desktop/core/lib/c.js | 4 | ||||
-rw-r--r-- | desktop/core/lib/i.js | 6 | ||||
-rw-r--r-- | desktop/core/lib/l.js | 2 | ||||
-rw-r--r-- | desktop/core/lib/t.js | 4 | ||||
-rw-r--r-- | desktop/core/lib/v.js | 4 | ||||
-rw-r--r-- | desktop/core/pico.js | 5 | ||||
-rw-r--r-- | examples/benchmark.pico | 14 |
9 files changed, 27 insertions, 22 deletions
diff --git a/desktop/core/lib/_base.js b/desktop/core/lib/_base.js index a37fbbf..5dec65b 100644 --- a/desktop/core/lib/_base.js +++ b/desktop/core/lib/_base.js @@ -4,7 +4,7 @@ function FnBase (pico, x, y, glyph = '.', passive = false) { this.x = x this.y = y this.passive = passive - this.name = '<missing name>' + this.name = 'unknown' this.glyph = passive ? glyph.toUpperCase() : glyph this.info = 'Missing docs.' this.ports = [] @@ -59,7 +59,7 @@ function FnBase (pico, x, y, glyph = '.', passive = false) { } this.toValue = function (g = '0') { - return g ? clamp(pico.allowed.indexOf(g.toLowerCase()), 0, pico.allowed.length) : 0 + return g ? clamp(pico.valueOf(g), 0, pico.allowed.length) : 0 } this.toChar = function (index = 0) { diff --git a/desktop/core/lib/_midi.js b/desktop/core/lib/_midi.js index bea63c7..6446a1d 100644 --- a/desktop/core/lib/_midi.js +++ b/desktop/core/lib/_midi.js @@ -28,9 +28,9 @@ function FnMidi (pico, x, y, passive) { if (channelGlyph === '.' || octaveGlyph === '.' || noteGlyph === '.') { return } if (notes.indexOf(noteGlyph) < 0) { return } - const channelValue = pico.allowed.indexOf(channelGlyph) - const octaveValue = pico.allowed.indexOf(octaveGlyph) - const noteValue = pico.allowed.indexOf(noteGlyph) + const channelValue = pico.valueOf(channelGlyph) + const octaveValue = pico.valueOf(octaveGlyph) + const noteValue = pico.valueOf(noteGlyph) const channel = clamp(channelValue, 0, 15) const octave = clamp(octaveValue, 2, 9) diff --git a/desktop/core/lib/c.js b/desktop/core/lib/c.js index f438530..d5e291e 100644 --- a/desktop/core/lib/c.js +++ b/desktop/core/lib/c.js @@ -22,8 +22,8 @@ function FnC (pico, x, y, passive) { const e = this.east() const s = this.south() - const min = w ? pico.allowed.indexOf(w.glyph) : 0 - const max = e ? pico.allowed.indexOf(e.glyph) : 9 + const min = w ? pico.valueOf(w.glyph) : 0 + const max = e ? pico.valueOf(e.glyph) : 9 const result = (pico.f % max) + min pico.add(this.x, this.y + 1, `${pico.allowed[result]}`) diff --git a/desktop/core/lib/i.js b/desktop/core/lib/i.js index fbd72c5..acdbcba 100644 --- a/desktop/core/lib/i.js +++ b/desktop/core/lib/i.js @@ -22,9 +22,9 @@ function FnI (pico, x, y, passive) { const e = this.east() const s = this.south() - const min = w ? pico.allowed.indexOf(w.glyph) : 0 - const max = e ? pico.allowed.indexOf(e.glyph) : 9 - const val = s ? pico.allowed.indexOf(s.glyph) : 0 + const min = w ? pico.valueOf(w.glyph) : 0 + const max = e ? pico.valueOf(e.glyph) : 9 + const val = s ? pico.valueOf(s.glyph) : 0 const result = val + 1 >= max ? min : val + 1 diff --git a/desktop/core/lib/l.js b/desktop/core/lib/l.js index 76f6ff4..8242965 100644 --- a/desktop/core/lib/l.js +++ b/desktop/core/lib/l.js @@ -11,7 +11,7 @@ function FnL (pico, x, y, passive) { if (pico) { this.w = this.west() - this.len = this.w ? pico.allowed.indexOf(this.w.glyph) : 0 + this.len = this.w ? pico.valueOf(this.w.glyph) : 0 for (let x = 1; x <= this.len; x++) { this.ports.push({ x: x, y: 0, output: true }) } diff --git a/desktop/core/lib/t.js b/desktop/core/lib/t.js index b9c7781..2a4547b 100644 --- a/desktop/core/lib/t.js +++ b/desktop/core/lib/t.js @@ -11,9 +11,9 @@ function FnT (pico, x, y, passive) { if (pico) { this.lenCh = pico.glyphAt(this.x - 1, this.y) - this.len = this.lenCh ? pico.allowed.indexOf(this.lenCh) : 0 + this.len = this.lenCh ? pico.valueOf(this.lenCh) : 0 this.valCh = pico.glyphAt(this.x - 2, this.y) - this.val = this.valCh ? pico.allowed.indexOf(this.valCh) : 0 + this.val = this.valCh ? pico.valueOf(this.valCh) : 0 if (this.lenCh === '.' || this.valCh === '.') { return } diff --git a/desktop/core/lib/v.js b/desktop/core/lib/v.js index 8466fd4..664cc5a 100644 --- a/desktop/core/lib/v.js +++ b/desktop/core/lib/v.js @@ -13,7 +13,7 @@ function FnV (pico, x, y, passive) { if (pico) { this.w = this.west() - this.len = this.w ? pico.allowed.indexOf(this.w.glyph) : 0 + this.len = this.w ? pico.valueOf(this.w.glyph) : 0 for (let x = 1; x <= this.len; x++) { this.ports.push({ x: x, y: 0, input: true }) } @@ -33,7 +33,7 @@ function FnV (pico, x, y, passive) { const g = pico.glyphAt(this.x + x, this.y) if (g !== '.') { count++ } } - const ch = pico.allowed.indexOf(`${count}`) + const ch = pico.valueOf(`${count}`) pico.add(this.x, this.y + 1, `${pico.allowed[ch]}`) } } diff --git a/desktop/core/pico.js b/desktop/core/pico.js index 1c7d392..55e6efa 100644 --- a/desktop/core/pico.js +++ b/desktop/core/pico.js @@ -103,6 +103,7 @@ function Pico (w, h) { const glyph = ch.substr(0, 1) if (!this.isAllowed(glyph)) { this.terminal.log(`[${glyph},${ch}] is not allowed`); return } if (!this.inBounds(x, y)) { this.terminal.log(`[${glyph}] is out of range`); return } + if (this.glyphAt(x, y) === ch) { return } const index = this.indexAt(x, y) this.s = this.s.substr(0, index) + glyph + this.s.substr(index + glyph.length) } @@ -130,6 +131,10 @@ function Pico (w, h) { return this.lib.alpha[g.toLowerCase()] || this.lib.num[g] || this.lib.special[g] } + this.valueOf = function (g) { + return this.isAllowed(`${g}`) ? pico.allowed.indexOf(`${g}`.toLowerCase()) : 0 + } + this.glyphAt = function (x, y, req = null) { return this.s.charAt(this.indexAt(x, y)) } diff --git a/examples/benchmark.pico b/examples/benchmark.pico index 1fa3d1e..5fb34c2 100644 --- a/examples/benchmark.pico +++ b/examples/benchmark.pico @@ -1,22 +1,22 @@ ................................................. -....A.......M.......F.......Y.......I.......C.... +....A.......C.......F.......I.......M.......Y.... ................................................. ................................................. -...2A......2M......2F......2Y......2I......2C.... +...2A......2C......2F......2I......2M......2Y.... ................................................. ................................................. -....A2......M2......F2......Y2......I2......C2... +....A2......C2......F2......I2......M2......Y2... ................................................. ................................................. -...2A2.....2M2.....2F2.....2Y2.....2I2.....2C2... +...2A2.....2C2.....2F2.....2I2.....2M2.....2Y2... ................................................. ................................................. -...2A3.....2M3.....2F3.....2Y3.....2I3.....2C3... +...2A3.....2C3.....2F3.....2I3.....2M3.....2Y3... ................................................. ................................................. -...2AK.....9MK.....2FK.....2YK.....2IK.....2CK... +...2AK.....2CK.....2FK.....2IK.....9MK.....2YK... ................................................. ................................................. -...KA2.....KM6.....KFK.....KYK.....KI2.....KC2... +...KA2.....KC2.....KFK.....KI2.....KM6.....KYK... ................................................. .................................................
\ No newline at end of file |