/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/tango-dom.d

  • 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:
4
4
import tango.io.Stdout;
5
5
import tango.text.xml.Document;
6
6
import tango.text.xml.DocPrinter;
 
7
import Float = tango.text.convert.Float;
7
8
 
8
9
import tools;
9
10
 
10
11
Document!(char) doc = null;
11
12
 
 
13
double walker_process_node(doc.Node cur_node) {
 
14
    double res;
 
15
    
 
16
    auto value = cur_node.value();
 
17
    if (value) {
 
18
        try {
 
19
            res = Float.toFloat(value); //Float.parse(value);
 
20
            if (res) return res;
 
21
        } catch {
 
22
        }
 
23
    }
 
24
    
 
25
 
 
26
    foreach (cur_attr; cur_node.attributes) {
 
27
        auto value = cur_attr.value();
 
28
        if (value) {
 
29
            try {
 
30
                res = Float.toFloat(value); //Float.parse(value);
 
31
                if (res) return res;
 
32
            } catch {
 
33
            }
 
34
        }
 
35
    }
 
36
    
 
37
    return 0;
 
38
}
 
39
 
 
40
//double walker(XmlPath!(char).NodeSet node) {
 
41
double walker(doc.Node node) {
 
42
    int i = 0;
 
43
    double res = 0;
 
44
    doc.Node cur_node;
 
45
 
 
46
//    foreach (cur_node; node) {
 
47
    for (cur_node = node; cur_node; cur_node = cur_node.next) {
 
48
        if (++i>3) break;
 
49
    }
 
50
    
 
51
    if (i<=3) i = 0;
 
52
 
 
53
//    foreach (cur_node; node) {
 
54
    for (cur_node = node; cur_node; cur_node = cur_node.next) {
 
55
//      Stdout(node.name(), ":", cur_node.name(), "\n");
 
56
        if (cur_node.type() is XmlNodeType.Element) {
 
57
            if (i) {
 
58
                res += walker_process_node(cur_node);
 
59
            }
 
60
            res+=walker(cur_node.child());
 
61
//          res+=walker(cur_node.query.child());
 
62
        }
 
63
    }
 
64
    return res;
 
65
}
 
66
 
 
67
 
 
68
 
 
69
 
12
70
extern(C) void initXML(TestData *td) {
13
71
    doc = new Document!(char);
14
72
}
18
76
 
19
77
extern(C) void parseXML(TestData *td, uint iter) {
20
78
    doc.parse(td.xml[0..td.xmllen]);
 
79
    if (get_walk_mode()) {
 
80
//      double res = walker(doc.elements.query.child());
 
81
        double res = walker(doc.elements.child());
 
82
//      Stdout(res);Stdout("\n");
 
83
    }
21
84
/*
22
85
    auto print = new DocPrinter!(char);
23
86
    Stdout(print(doc)).newline;