Project

Profile

Help

Bug #3555

Updated by Michael Kay almost 4 years ago

The "castable as" operator is implemented essentially as 


 


 ~~~ 
 
 try { targetType.cast(input); return true } catch { return false }; 
 
 ~~~ 

 

 Throwing and catching exceptions is expensive and this shows up in performance profiles. 


 


 An alternative would be for Atomic.cast() functions to accept an optional second argument onError whose value is a function that is called if casting is not possible; this needs to be passed through to functions such as fromString() and fromDouble() that do the cast, and thence to the two functions invalidValue() and disallowedCast() which actually throw the error. The implementation of "castable" could then be changed to: 


 


 ~~~ 
 
 var result = true; targetType.cast(input, function(){ result = false }) 
 
 ~~~ 
 

Back