Chameleon

Chameleon Commit Details

Date:2014-01-12 07:07:57 (5 years 11 months ago)
Author:Chuck Fry
Commit:2338
Parents: 2337
Message:Use sizeof() instead of strlen() for tag names known at compile time
Changes:
M/branches/chucko/i386/libsaio/xml.h
M/branches/chucko/i386/libsaio/xml.c

File differences

branches/chucko/i386/libsaio/xml.c
2727
2828
2929
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
3058
3159
3260
......
350378
351379
352380
353
354
381
382
355383
356384
357385
358
386
359387
360388
361
389
362390
363391
364392
365
393
394
366395
367396
368
397
369398
370399
371400
......
383412
384413
385414
386
415
387416
388417
389418
......
426455
427456
428457
429
430
458
459
431460
432461
433462
434
463
435464
436
465
437466
438467
439468
......
458487
459488
460489
461
490
462491
463492
464493
......
518547
519548
520549
521
550
522551
523552
524553
525554
526555
527
528
556
557
529558
530559
531560
532
561
533562
534563
535564
......
541570
542571
543572
544
545
546
573
574
575
547576
548577
549578
550579
551580
552
553
554
581
582
583
555584
556585
557586
558587
559588
560
561
589
590
562591
563592
564593
#include "sl.h"
#include "xml.h"
#define kXMLTagPList "plist "
#define kXMLTagPListLen (sizeof(kXMLTagPList) - 1)
#define kXMLTagDict "dict"
#define kXMLTagDictLen (sizeof(kXMLTagDict) - 1)
#define kXMLTagKey "key"
#define kXMLTagKeyLen (sizeof(kXMLTagKey) - 1)
#define kXMLTagString "string"
#define kXMLTagStringLen (sizeof(kXMLTagString) - 1)
#define kXMLTagInteger "integer"
#define kXMLTagIntegerLen (sizeof(kXMLTagInteger) - 1)
#define kXMLTagData "data"
#define kXMLTagDataLen (sizeof(kXMLTagData) - 1)
#define kXMLTagDate "date"
#define kXMLTagDateLen (sizeof(kXMLTagDate) - 1)
#define kXMLTagFalse "false/"
#define kXMLTagFalseLen (sizeof(kXMLTagFalse) - 1)
#define kXMLTagTrue "true/"
#define kXMLTagTrueLen (sizeof(kXMLTagTrue) - 1)
#define kXMLTagArray "array"
#define kXMLTagArrayLen (sizeof(kXMLTagArray) - 1)
// for back-references used by libkern serializer
#define kXMLTagReference "reference"
#define kXMLTagReferenceLen (sizeof(kXMLTagReference) - 1)
#define kXMLStringID "ID="
#define kXMLStringIDLen (sizeof(kXMLStringID) - 1)
#define kXMLStringIDRef "IDREF="
#define kXMLStringIDRefLen (sizeof(kXMLStringIDRef) - 1)
string_ref *ref_strings = NULL;
/// TODO: remove below
}
/***** string ****/
else if (!strncmp(tagName, kXMLTagString, strlen(kXMLTagString))) {
if (!tagName[strlen(kXMLTagString)]) /* <string> */
else if (!strncmp(tagName, kXMLTagString, kXMLTagStringLen)) {
if (!tagName[kXMLTagStringLen]) /* <string> */
{
length = ParseTagString(buffer + pos, tag);
}
else if (' ' == tagName[strlen(kXMLTagString)]) /* <string ...> */
else if (' ' == tagName[kXMLTagStringLen]) /* <string ...> */
{
// TODO: save tag if if found
if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringID, strlen(kXMLStringID))) /* <string ID= ...> */
if(!strncmp(tagName + kXMLTagStringLen + 1, (kXMLStringID "\""), kXMLStringIDLen + 1)) /* <string ID="...> */
{
// ID=
int id = 0;
int cnt = strlen(kXMLTagString " " kXMLStringID "\"") + 1;
/* find end of ID string */
int cnt = kXMLTagStringLen + 1 + kXMLStringIDLen + 2;
while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
tagName[cnt] = 0;
char* val = tagName + strlen(kXMLTagString " " kXMLStringID "\"");
char* val = tagName + kXMLTagStringLen + 1 + kXMLStringIDLen + 1;
while(*val)
{
if ((*val >= '0' && *val <= '9'))// 0 - 9
SaveRefString(buffer + pos, id);
}
else if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringIDRef, strlen(kXMLStringIDRef))) /* <string IDREF= ...> */
else if(!strncmp(tagName + kXMLTagStringLen + 1, kXMLStringIDRef, kXMLStringIDRefLen)) /* <string IDREF= ...> */
{
// IDREF=
int id = 0;
}
/***** integer ****/
else if (!strncmp(tagName, kXMLTagInteger, strlen(kXMLTagInteger))) {
if (!tagName[strlen(kXMLTagInteger)]) /* <integer> */
else if (!strncmp(tagName, kXMLTagInteger, kXMLTagIntegerLen)) {
if (!tagName[kXMLTagIntegerLen]) /* <integer> */
{
length = ParseTagInteger(buffer + pos, tag);
}
else if (' ' == tagName[strlen(kXMLTagInteger)]) /* <integer ...> */
else if (' ' == tagName[kXMLTagIntegerLen]) /* <integer ...> */
{
if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringID, strlen(kXMLStringID))) /* <integer ID=...> */
if(!strncmp(tagName + kXMLTagIntegerLen + 1, kXMLStringID, kXMLStringIDLen)) /* <integer ID=...> */
{
// ID=
int id = 0;
SaveRefString((*tag)->string, id);
}
else if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringIDRef, strlen(kXMLStringIDRef))) /* <integer IDREF=...> */
else if(!strncmp(tagName + kXMLTagIntegerLen + 1, kXMLStringIDRef, kXMLStringIDRefLen)) /* <integer IDREF=...> */
{
// IDREF=
int id = 0;
}
/***** plist ****/
else if (!strncmp(tagName, kXMLTagPList, 6))
else if (!strncmp(tagName, kXMLTagPList, kXMLTagPListLen))
{
length = 0;
}
/***** dict ****/
else if (!strncmp(tagName, kXMLTagDict, strlen(kXMLTagDict))) {
if (!strncmp(tagName, kXMLTagDict, strlen(kXMLTagDict)) && tagName[strlen(tagName)-1] == '/') /* <dict.../> */
else if (!strncmp(tagName, kXMLTagDict, kXMLTagDictLen)) {
if (!strncmp(tagName, kXMLTagDict, kXMLTagDictLen) && tagName[strlen(tagName)-1] == '/') /* <dict.../> */
{
length = ParseTagList(buffer + pos, tag, kTagTypeDict, 1);
}
else if (!tagName[strlen(kXMLTagDict)] || ' ' == tagName[strlen(kXMLTagDict)]) /* <dict> or<dict ...> */
else if (!tagName[kXMLTagDictLen] || ' ' == tagName[kXMLTagDictLen]) /* <dict> or<dict ...> */
{
length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0);
}
}
/***** data ****/
else if ((!strncmp(tagName, kXMLTagData, strlen(kXMLTagData)))
&& (!tagName[strlen(kXMLTagData)] /* <data> */
|| ' ' == tagName[strlen(kXMLTagData)])) /* <data ...> */
else if ((!strncmp(tagName, kXMLTagData, kXMLTagDataLen))
&& (!tagName[kXMLTagDataLen] /* <data> */
|| ' ' == tagName[kXMLTagDataLen])) /* <data ...> */
{
length = ParseTagData(buffer + pos, tag);
}
/***** date ****/
else if ((!strncmp(tagName, kXMLTagDate, strlen(kXMLTagDate)))
&& (!tagName[strlen(kXMLTagDate)] /* <date> */
|| ' ' == tagName[strlen(kXMLTagDate)])) /* <date ...> */
else if ((!strncmp(tagName, kXMLTagDate, kXMLTagDateLen))
&& (!tagName[kXMLTagDateLen] /* <date> */
|| ' ' == tagName[kXMLTagDateLen])) /* <date ...> */
{
length = ParseTagDate(buffer + pos, tag);
}
/***** array ****/
else if (!strncmp(tagName, kXMLTagArray, strlen(kXMLTagArray))) { /* <array...> */
char c = tagName[strlen(kXMLTagArray)];
else if (!strncmp(tagName, kXMLTagArray, kXMLTagArrayLen)) { /* <array...> */
char c = tagName[kXMLTagArrayLen];
if ('/' == c) /* <array/> */
{
length = ParseTagList(buffer + pos, tag, kTagTypeArray, 1);
branches/chucko/i386/libsaio/xml.h
4848
4949
5050
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
6651
6752
6853
extern string_ref* ref_strings;
#define kXMLTagPList "plist "
#define kXMLTagDict "dict"
#define kXMLTagKey "key"
#define kXMLTagString "string"
#define kXMLTagInteger "integer"
#define kXMLTagData "data"
#define kXMLTagDate "date"
#define kXMLTagFalse "false/"
#define kXMLTagTrue "true/"
#define kXMLTagArray "array"
// for back-references used by libkern serializer
#define kXMLTagReference "reference"
#define kXMLStringID "ID="
#define kXMLStringIDRef "IDREF="
#define kPropCFBundleIdentifier ("CFBundleIdentifier")
#define kPropCFBundleExecutable ("CFBundleExecutable")
#define kPropOSBundleRequired ("OSBundleRequired")

Archive Download the corresponding diff file

Revision: 2338