/xmlbench/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/xmlbench/trunk

« back to all changes in this revision

Viewing changes to parse/intel-dom.cpp

  • Committer: Suren A. Chilingaryan
  • Date: 2009-10-01 15:56:11 UTC
  • Revision ID: csa@dside.dyndns.org-20091001155611-9g3f1yad2w195t4g
Implement DOM walking mode for parsing benchmark in fast parsers

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
DOMImplementation* domimpl;
21
21
DOMParser* parser;
22
22
 
 
23
 
 
24
inline double walker_process_node(Node *cur_node) {
 
25
    double res;
 
26
    Node *child;
 
27
    
 
28
    child = cur_node->getFirstChild();
 
29
    if ((child)&&(child->getNodeType() == Node::TEXT_NODE)) {
 
30
        res = get_value(child->getNodeValue());
 
31
        if (res) return res;
 
32
    } 
 
33
 
 
34
    NamedNodeMap* attrMap = cur_node->getAttributes();
 
35
    unsigned int length = attrMap->getLength();
 
36
 
 
37
    for (unsigned int i = 0; i < length; i++) {
 
38
        Attr* attr=(Attr*)attrMap->item(i);
 
39
        res = get_value(attr->getNodeValue());
 
40
        if (res) return res;
 
41
    }
 
42
 
 
43
    return 0;
 
44
}
 
45
 
 
46
 
 
47
double walker(Node *node) {
 
48
    int i = 0;
 
49
    double res = 0;
 
50
    Node *cur_node;
 
51
 
 
52
    for (cur_node = node; cur_node; cur_node = cur_node->getNextSibling()) {
 
53
        if((cur_node->getNodeType() == Node::ELEMENT_NODE)&&(++i>3)) break;
 
54
    }
 
55
    
 
56
    if (i<=3) i = 0;
 
57
 
 
58
    for (cur_node = node; cur_node; cur_node = cur_node->getNextSibling()) {
 
59
        if (cur_node->getNodeType() == Node::ELEMENT_NODE) {
 
60
            if (i) {
 
61
                res += walker_process_node(cur_node);
 
62
            }
 
63
            res+=walker(cur_node->getFirstChild());
 
64
        }
 
65
    }
 
66
    return res;
 
67
}
 
68
 
 
69
 
23
70
void initXML(struct TestData *td) {
24
71
    domfactory = DOMImplementationFactory::newInstance();
25
72
    domimpl = domfactory->getDOMImplementation();
41
88
    //buffer->setCopyBufToStream(false);
42
89
 
43
90
    doc = parser->parse(ss);
 
91
    if (walk_tree) {
 
92
        double res = walker(doc->getFirstChild());
 
93
//      printf("Sum: %lf\n", res);
 
94
    }
44
95
 
45
96
    delete ss;
46
97
    delete buffer;