2 docCopyright("Steve Dekorte", 2002)
3 docLicense("BSD revised")
11 #define MIN_CACHED_NUMBER -10
12 #define MAX_CACHED_NUMBER 256
14 // numbers ----------------------------------
16 void IoState_setupCachedNumbers(IoState
*self
)
20 self
->cachedNumbers
= List_new();
22 for (i
= MIN_CACHED_NUMBER
; i
< MAX_CACHED_NUMBER
+ 1; i
++)
24 IoNumber
*number
= IoNumber_newWithDouble_(self
, i
);
25 List_append_(self
->cachedNumbers
, number
);
26 IoState_retain_(self
, number
);
30 IoObject
*IoState_numberWithDouble_(IoState
*self
, double n
)
34 if (self
->cachedNumbers
&& i
== n
&& i
>= MIN_CACHED_NUMBER
&& i
<= MAX_CACHED_NUMBER
)
36 return List_at_(self
->cachedNumbers
, i
- MIN_CACHED_NUMBER
);
39 return IoNumber_newWithDouble_(self
, n
);
42 // strings ----------------------------------
45 IoSymbol
*IoState_symbolWithUArray_copy_(IoState
*self
, UArray
*ba
, int copy
)
47 IoSymbol
*ioSymbol
= SHash_at_(self
->symbols
, ba
);
51 ioSymbol
= IoSeq_newSymbolWithUArray_copy_(self
, ba
, copy
);
52 return IoState_addSymbol_(self
, ioSymbol
);
60 IoState_stackRetain_(self
, ioSymbol
);
64 IoSymbol
*IoState_symbolWithCString_length_(IoState
*self
, const char *s
, size_t length
)
66 UArray
*a
= UArray_newWithData_type_size_copy_((char *)s
, CTYPE_uint8_t
, length
, 1);
67 UArray_setEncoding_(a
, CENCODING_UTF8
);
68 UArray_convertToFixedSizeType(a
);
69 return IoState_symbolWithUArray_copy_(self
, a
, 0);
72 IoSymbol
*IoState_symbolWithCString_(IoState
*self
, const char *s
)
74 return IoState_symbolWithCString_length_(self
, s
, strlen(s
));
77 IoSymbol
*IoState_addSymbol_(IoState
*self
, IoSymbol
*s
)
79 SHash_at_put_(self
->symbols
, IoSeq_rawUArray(s
), s
);
80 IoObject_isSymbol_(s
, 1);
84 void IoState_removeSymbol_(IoState
*self
, IoSymbol
*s
)
86 SHash_removeKey_(self
->symbols
, IoSeq_rawUArray(s
));