stevedlawrence commented on a change in pull request #16: Implemented packed binary formats URL: https://github.com/apache/incubator-daffodil/pull/16#discussion_r161784951
########## File path: daffodil-lib/src/main/scala/edu/illinois/ncsa/daffodil/util/DecimalUtils.scala ########## @@ -0,0 +1,342 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package edu.illinois.ncsa.daffodil.util + +import edu.illinois.ncsa.daffodil.schema.annotation.props.gen.BinaryNumberCheckPolicy + +import java.math.{ BigInteger => JBigInteger, BigDecimal => JBigDecimal } + +object DecimalUtils { + + def signCodesToHex(signCodes: String, policy: BinaryNumberCheckPolicy): Map[String, List[Int]] = { Review comment: It looks like this function is going to be called at runtime to generate this Map. Which is going to be somewhat expensive. Additionally, the values used to generate this map come from dfdl:binaryPackedSignCodes and dfdl:binaryNumberCheckPolicy, both of which are static. Which means that this can be calculated a schema compile time and then passed and stored in the parsers/unparsers. Calculating this at runtime should minimize runtime overhead. Also, I'm not sure a Map is the right data structure. It looks like it will always only have four things in it: positive, negative, unsigned, and zero signed. Since there will only ever be four things, can we create a new data structure with four member variables? This avoids the overhead of hashing to store and look up hash table entries. You could use a companion object to have the logic of this function to create the class. So something like: ```scala object PackedSignCodes { apply(signCodes: String, policy: BinaryNumberCheckPolicy) = { // logic in this function here new PackedSignCodes(positive, negative, unsigned, zero_signed) } } case class PackedSignCodes( positive: List[Int], negative: List[Int], unsigned: List[Int], zero_signed: List[Int] ) {} ``` ---------------------------------------------------------------- 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: [email protected] With regards, Apache Git Services
