Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
3.4 KiB

  1. /*===========================================================================
  2. optcfg.h
  3. This header contains optimization settings for Parsifal library
  4. TODO
  5. A lot. Currently contains only inline versions of some routines to be
  6. selectively replaced in the critical areas of code. And yes, these
  7. critical areas are identified by running profiler ;-)
  8. ===========================================================================*/
  9. #ifdef _MSC_VER
  10. #define INLINE __forceinline
  11. #else
  12. #ifdef __GNUC__
  13. #define INLINE __inline__ __attribute__((always_inline))
  14. #else
  15. #define INLINE inline
  16. #endif
  17. #endif
  18. #define GROWSBUF_OPT(l) \
  19. if (sbuf->usePool) { \
  20. if ((sbuf->len + (l)) > sbuf->pool->itemSize) { \
  21. XMLCH *ts = sbuf->str; \
  22. sbuf->usePool = 0; \
  23. sbuf->capacity = COUNTBUFSIZE((sbuf->len + (l)), sbuf->blocksize); \
  24. sbuf->str = (XMLCH*)malloc(sbuf->capacity * sizeof(XMLCH)); \
  25. if (!sbuf->str) return ((XMLCH*)NULL); \
  26. memcpy(sbuf->str, ts, sbuf->len); \
  27. XMLPool_Free(sbuf->pool, ts); \
  28. } \
  29. } \
  30. else if ((sbuf->len + (l)) > sbuf->capacity) { \
  31. sbuf->capacity = COUNTBUFSIZE((sbuf->len + (l)), sbuf->blocksize); \
  32. sbuf->str = (XMLCH*)realloc(sbuf->str, sbuf->capacity * sizeof(XMLCH)); \
  33. if (!sbuf->str) return ((XMLCH*)NULL); \
  34. }
  35. static INLINE XMLCH *XMLStringbuf_Append_Opt(LPXMLSTRINGBUF sbuf, XMLCH *str, int len)
  36. {
  37. GROWSBUF_OPT(len);
  38. if (len == 1) /* gives a slight performance gain */
  39. sbuf->str[sbuf->len++] = *str;
  40. else {
  41. memcpy(sbuf->str+sbuf->len, str, len);
  42. sbuf->len += len;
  43. }
  44. return (sbuf->str);
  45. }
  46. static INLINE XMLCH *ReadCh_Opt(LPXMLPARSER parser, int *chSize)
  47. {
  48. XMLCH *c;
  49. int ret;
  50. if (!PREADER->buf || PREADER->pos >= PREADER->bytesavail) {
  51. ret = PEEKINPUT((const BYTE*)NULL, 1);
  52. if (EINPUT(ret) || ret) {
  53. #ifdef DTD_SUPPORT
  54. if (RT->dtd && !parser->ErrorCode &&
  55. RT->dtd->peStack->length &&
  56. ((*((LPBUFFEREDISTREAM*)STACK_PEEK(RT->dtd->peStack)))) == PREADER)
  57. return ReadPERefEnd(parser, chSize);
  58. else {
  59. #endif
  60. *chSize = 0;
  61. return (XMLCH*)NULL;
  62. #ifdef DTD_SUPPORT
  63. }
  64. #endif
  65. }
  66. }
  67. c = PREADER->buf+PREADER->pos;
  68. UTF8LEN(c,*chSize);
  69. if (*chSize == 1) {
  70. if (ISILLBYTE(*c)) {
  71. *chSize = 0;
  72. ErP_(parser, ERR_XMLP_ILLEGAL_CHAR, 1);
  73. return (XMLCH*)NULL;
  74. }
  75. PREADER->pos++;
  76. if (*c == 0xD) {
  77. PREADERDATA->line++;
  78. PREADERDATA->col=0;
  79. PREADER->buf[PREADER->pos-1] = 0xA;
  80. if (PREADER->pos >= PREADER->bytesavail) {
  81. ret = PEEKINPUT((const BYTE*)NULL, 1);
  82. if (EINPUT(ret)) {
  83. *chSize = 0;
  84. return (XMLCH*)NULL;
  85. }
  86. c = PREADER->buf+(PREADER->pos-1);
  87. if (ret) return(c);
  88. }
  89. if (CURCHAR == 0xA) PREADER->pos++;
  90. }
  91. else if (*c == 0xA) {
  92. PREADERDATA->line++;
  93. PREADERDATA->col=0;
  94. }
  95. #ifdef DTD_SUPPORT
  96. else if (*c == '%' && RT->dtd && RT->dtd->expandPEs) {
  97. PREADERDATA->col++;
  98. c = ReadPERefStart(parser, chSize);
  99. }
  100. #endif
  101. else PREADERDATA->col++;
  102. }
  103. else {
  104. if (*chSize == 3 && UTF8_ISILL3(c)) {
  105. *chSize = 0;
  106. ErP_(parser, ERR_XMLP_ILLEGAL_CHAR, 0);
  107. return (XMLCH*)NULL;
  108. }
  109. else if (*chSize == 4 && UTF8_ISILL4(c)) {
  110. *chSize = 0;
  111. ErP_(parser, ERR_XMLP_ILLEGAL_CHAR, 0);
  112. return (XMLCH*)NULL;
  113. }
  114. PREADER->pos += *chSize;
  115. PREADERDATA->col += *chSize;
  116. }
  117. return(c);
  118. }