Index php_ctpp cpp --- php_ctpp cpp revision 24 php_ctpp cpp working c

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
Index: php_ctpp.cpp
===================================================================
--- php_ctpp.cpp (revision 24)
+++ php_ctpp.cpp (working copy)
@@ -1778,53 +1778,48 @@
CHAR_8 szNumKey[1024 + 1];
CDT * pCDT = (CTPP::CDT *)va_arg(args, void *);
+ bool * is_first = (bool *)va_arg(args, bool *);
+ ulong * last_key = (ulong *)va_arg(args, ulong *);
uint uiKeyLen = 0;
CDT oTMP;
-
- /* Import data */
+
+ bool is_hash = (
+ pCDT->GetType() == CDT::HASH_VAL ||
+ hash_key->nKeyLength > 0 ||
+ (
+ hash_key->nKeyLength == 0 &&
+ (
+ (*is_first && hash_key->h != 0) ||
+ (!*is_first && hash_key->h - *last_key != 1)
+ )
+ )
+ );
_php_import_value(pDataSet, &oTMP);
-
- /* Key of PHP array is numeric */
- if (hash_key -> nKeyLength == 0)
- {
- /* ARRAY */
- const CDT::eValType eType = pCDT -> GetType();
- if (eType == CDT::ARRAY_VAL || eType == CDT::UNDEF)
- {
- /* Push element */
- pCDT -> operator[](pCDT -> Size()) = oTMP;
- }
- /* HASH */
- else /* if (pCDT -> GetType() == CDT::HASH_VAL) */
- {
- /* Map long int to char key */
- uiKeyLen = snprintf(szNumKey, 1024, "%ld", hash_key -> h);
- pCDT -> operator[](STLW::string(szNumKey, uiKeyLen)) = oTMP;
- }
- }
- /* Key of PHP array is string */
- else
- {
- /* ARRAY */
- const CDT::eValType eType = pCDT -> GetType();
- if (eType == CDT::ARRAY_VAL || eType == CDT::UNDEF)
- {
- /* Convert from ARRAY to HASH */
+
+ if (is_hash) {
+ const CDT::eValType eType = pCDT->GetType();
+ if (eType == CDT::ARRAY_VAL) {
CDT oTMPArray;
- const UINT_32 iSize = pCDT -> Size();
- for (UINT_32 iPos = 0; iPos < iSize; ++iPos)
- {
+ const UINT_32 iSize = pCDT->Size();
+ for (UINT_32 iPos = 0; iPos < iSize; ++iPos) {
uiKeyLen = snprintf(szNumKey, 1024, "%d", iPos);
- oTMPArray[STLW::string(szNumKey, uiKeyLen)] = pCDT -> operator[](iPos);
+ oTMPArray[STLW::string(szNumKey, uiKeyLen)] = pCDT->operator[](iPos);
}
-
- pCDT -> operator=(oTMPArray);
+ pCDT->operator=(oTMPArray);
}
-
- pCDT -> operator[](STLW::string(hash_key -> arKey, hash_key -> nKeyLength - 1)) = oTMP;
+ if (hash_key->nKeyLength == 0) {
+ uiKeyLen = snprintf(szNumKey, 1024, "%ld", hash_key->h);
+ pCDT->operator[](STLW::string(szNumKey, uiKeyLen)) = oTMP;
+ } else
+ pCDT->operator[](STLW::string(hash_key->arKey, hash_key->nKeyLength - 1)) = oTMP;
+ } else {
+ pCDT->operator[](pCDT -> Size()) = oTMP;
+ *last_key = hash_key->h;
}
-
-return 0;
+
+ if (*is_first)
+ *is_first = false;
+ return 0;
}
/* Add parameters */
@@ -1876,8 +1871,10 @@
pCDT -> operator=("*RECURSION*");
return IS_NULL;
}
-
- zend_hash_apply_with_arguments(pHashTable TSRMLS_CC, (apply_func_args_t)_php_array_element_dump, 1, pCDT);
+ bool is_first = true;
+ ulong last_key = 0;
+
+ zend_hash_apply_with_arguments(pHashTable TSRMLS_CC, (apply_func_args_t)_php_array_element_dump, 3, pCDT, &is_first, &last_key);
}
return IS_ARRAY;