mbeckerle commented on a change in pull request #12: Revised daffodil-io module to require passing in a FormatInfo object. URL: https://github.com/apache/incubator-daffodil/pull/12#discussion_r158078991
########## File path: daffodil-io/src/main/scala/edu/illinois/ncsa/daffodil/io/DataOutputStreamImplMixin.scala ########## @@ -843,26 +736,49 @@ trait DataOutputStreamImplMixin extends DataStreamCommonState private val unionIntBuffer = unionByteBuffer.asIntBuffer() protected val unionLongBuffer = unionByteBuffer.asLongBuffer() - def putBinaryFloat(v: Float, finfo: FormatInfo): Boolean = { + final override def putBinaryFloat(v: Float, finfo: FormatInfo): Boolean = { unionFloatBuffer.put(0, v) val i = unionIntBuffer.get(0) - putLong(i, 32, finfo) + val res = putLongChecked(i, 32, finfo) + setPriorBitOrder(finfo.bitOrder) + res } - def putBinaryDouble(v: Double, finfo: FormatInfo): Boolean = { + final override def putBinaryDouble(v: Double, finfo: FormatInfo): Boolean = { unionDoubleBuffer.put(0, v) val l = unionLongBuffer.get(0) - putLong(l, 64, finfo) + val res = putLongChecked(l, 64, finfo) + setPriorBitOrder(finfo.bitOrder) + res } - def skip(nBits: Long, finfo: FormatInfo): Boolean = { + /** + * Used when we have to fill in things that are larger or smaller than a byte + */ + private def fillLong(fillByte: Byte) = { + var fl: Long = 0L + val fb = fillByte.toInt & 0xFF + fl = (fl << 8) + fb + fl = (fl << 8) + fb + fl = (fl << 8) + fb + fl = (fl << 8) + fb + fl = (fl << 8) + fb + fl = (fl << 8) + fb + fl = (fl << 8) + fb + fl = (fl << 8) + fb + fl + } Review comment: To keep things simple I figured the above should be faster than pretty much anything else we could do, particularly since Evaluatables will involve virtual-method calls, etc. So, yeah, I'd say pre-optimization and we should see if we're recomputing fillLong and noticing it somewhere. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services