Skip to content

Commit

Permalink
no need for special casing it
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Jan 13, 2025
1 parent ef77a2e commit ec4b2f0
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions lib/view.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const { Readable, getStreamError } = require('streamx')
const b4a = require('b4a')

const DROPPED = [null, null, null]

class OverlayStream extends Readable {
constructor (stream, start, end, reverse, changes, ranges) {
super()
Expand Down Expand Up @@ -141,10 +139,6 @@ class Overlay {
changes.sort(cmp)
ranges.sort(cmp)

while (changes.length > 0 && changes[changes.length - 1] === DROPPED) {
changes.pop()
}

this.indexed = view.indexed
this.changes = changes
this.ranges = ranges
Expand Down Expand Up @@ -268,8 +262,8 @@ class View {
const s = b4a.toString(range[0], 'hex')
const e = b4a.toString(range[2], 'hex')

for (const key of this.map.keys()) {
if (s <= key && key < e) this.map.set(key, DROPPED)
for (const [key, c] of this.map) {
if (s <= key && key < e) this.map.set(key, [c[0], null, null])
}

if (this.ranges === null) this.ranges = []
Expand Down Expand Up @@ -315,9 +309,6 @@ class View {
module.exports = View

function cmpChange (a, b) {
if (a === DROPPED) return b === DROPPED ? 0 : 1
if (b === DROPPED) return a === DROPPED ? 0 : -1

const c = b4a.compare(a[0], b[0])
return c === 0 ? b4a.compare(a[2], b[2]) : c
}
Expand Down

0 comments on commit ec4b2f0

Please sign in to comment.