more list comprehensions

This commit is contained in:
Howland Owl 2013-10-17 16:28:54 +03:00
parent 89816ca1e6
commit c2baa5e28f

View file

@ -937,16 +937,16 @@ class @ImageTextMode
shrt = ( @getByteAt( data, 1 ) << 8 ) + @getByteAt( data, 0 ) shrt = ( @getByteAt( data, 1 ) << 8 ) + @getByteAt( data, 0 )
if shrt < 0 if shrt < 0
shrt += 65536 shrt += 65536
return shrt shrt
unpackLong: ( data ) -> unpackLong: ( data ) ->
lng = ((( @getByteAt( data, 0 ) << 8 ) + @getByteAt( data, 1 ) << 8 ) + @getByteAt( data, 2 ) << 8 ) + @getByteAt( data, 3 ) lng = ((( @getByteAt( data, 0 ) << 8 ) + @getByteAt( data, 1 ) << 8 ) + @getByteAt( data, 2 ) << 8 ) + @getByteAt( data, 3 )
if lng < 0 if lng < 0
lng += 4294967296 lng += 4294967296
return lng; lng;
getByteAt: ( data, offset ) -> getByteAt: ( data, offset ) ->
return data.charCodeAt( offset ) & 0xFF data.charCodeAt( offset ) & 0xFF
# could we replace this with math.max ? Not worth it,called once per view # could we replace this with math.max ? Not worth it,called once per view
# we COULD, but we'd do some crap like "Math.max.apply(null,blah) and that's not readable" # we COULD, but we'd do some crap like "Math.max.apply(null,blah) and that's not readable"
@ -954,7 +954,7 @@ class @ImageTextMode
max = 0 max = 0
for y in [ 0 .. @screen.length - 1 ] for y in [ 0 .. @screen.length - 1 ]
max = @screen[ y ].length if @screen[ y ]? && @screen[ y ].length > max max = @screen[ y ].length if @screen[ y ]? && @screen[ y ].length > max
return max max
getHeight: -> getHeight: ->
@screen.length @screen.length
@ -1027,16 +1027,9 @@ class @ImageTextMode
toBinaryArray: (str) -> toBinaryArray: (str) ->
buf = new ArrayBuffer(str.length * 2) # 2 bytes for each char buf = new ArrayBuffer(str.length * 2) # 2 bytes for each char
bufView = new Uint8Array(buf) bufView = new Uint8Array(buf)
i = 0 bufView[i] = str.charCodeAt(i) for i in [0...str.length]
strLen = str.length
while i < strLen
bufView[i] = str.charCodeAt(i)
i++
buf buf
class @ImageTextModeXBin extends @ImageTextMode class @ImageTextModeXBin extends @ImageTextMode
# Header constants # Header constants