Don't create the text collection during parsing but afterwards.
[SXSI/XMLTree.git] / XMLTreeBuilder.cpp
index 0fc8d32..d9b0832 100644 (file)
@@ -68,25 +68,13 @@ XMLTree *XMLTreeBuilder::CloseDocument()
    STOPTIMER(Parsing);\r
    PRINTTIME("Parsing XML Document", Parsing);\r
 \r
-    if (!disable_tc) {\r
-       assert(Text == 0);\r
-       assert(TextBuilder != 0);\r
-       STARTTIMER();\r
-       Text = TextBuilder->InitTextCollection();\r
-       delete TextBuilder;\r
-       TextBuilder = 0;\r
-       STOPTIMER(Building);\r
-       PRINTTIME("Building TextCollection", Building);\r
-\r
-    }\r
-\r
     XMLTree *T = new XMLTree(par_aux,\r
                             npar,\r
                             TagName,\r
                             tIdMap,\r
                             empty_texts_aux, // freed by the constructor\r
                             tags_aux,        // freed by the constructor\r
-                            Text,\r
+                            TextBuilder,     // freed by the constructor\r
                             disable_tc,\r
                             text_index_type);\r
     tags_aux = 0;\r
@@ -101,14 +89,18 @@ XMLTree *XMLTreeBuilder::CloseDocument()
 int XMLTreeBuilder::NewOpenTag(string tagname)\r
  {\r
     int i;\r
-\r
     // inserts a new opening parentheses in the bit sequence\r
     if (sizeof(pb)*8*parArraySize == npar) { // no space left for the new parenthesis\r
-       par_aux = (pb *)urealloc(par_aux, sizeof(pb)*2*parArraySize);\r
-       parArraySize *= 2;\r
-    }\r
 \r
-    setbit(par_aux,npar,OP);  // marks a new opening parenthesis\r
+      // If array is already 1GB, be gentler when resizing:\r
+      if (sizeof(pb)*parArraySize >= 1024*1024*1024)\r
+       parArraySize += (128*1024*1024);\r
+      else\r
+       parArraySize *= 2;\r
+      par_aux = (pb *) urealloc(par_aux, sizeof(pb)*parArraySize);\r
+    };\r
+\r
+    bp_setbit(par_aux,npar,OP);  // marks a new opening parenthesis\r
 \r
     TagIdMapIT tag_id = tIdMap->find(tagname);\r
 \r
@@ -123,6 +115,7 @@ int XMLTreeBuilder::NewOpenTag(string tagname)
        tagname.compare(ATTRIBUTE_DATA_OPEN_TAG) == 0){\r
     };\r
 \r
+\r
     tags_aux = (TagType *) urealloc(tags_aux, sizeof(TagType)*(npar + 1));\r
 \r
     tags_aux[npar] = i; // inserts the new tag id within the preorder sequence of tags\r
@@ -139,14 +132,17 @@ int XMLTreeBuilder::NewOpenTag(string tagname)
 int XMLTreeBuilder::NewClosingTag(string tagname)\r
  {\r
     int i;\r
-\r
     // inserts a new closing parentheses in the bit sequence\r
     if (sizeof(pb)*8*parArraySize == npar) { // no space left for the new parenthesis\r
-       par_aux = (pb *)urealloc(par_aux, sizeof(pb)*2*parArraySize);\r
-       parArraySize *= 2;\r
-    }\r
+      // If array is already 1GB, be gentler when resizing:\r
+      if (sizeof(pb)*parArraySize >= 1024*1024*1024)\r
+       parArraySize += (128*1024*1024);\r
+      else\r
+       parArraySize *= 2;\r
+      par_aux = (pb *)urealloc(par_aux, sizeof(pb)*parArraySize);\r
+    };\r
 \r
-    setbit(par_aux,npar,CP);  // marks a new closing parenthesis\r
+    bp_setbit(par_aux,npar,CP);  // marks a new closing parenthesis\r
 \r
     //tagname.insert(0,"/");\r
 \r
@@ -159,7 +155,7 @@ int XMLTreeBuilder::NewClosingTag(string tagname)
     // else\r
     //   i = tag_id->second;\r
 \r
-    tags_aux = (TagType *)urealloc(tags_aux, sizeof(TagType)*(npar + 1));\r
+      tags_aux = (TagType *)urealloc(tags_aux, sizeof(TagType)*(npar + 1));\r
 \r
     tags_aux[npar] = CLOSING_TAG_ID; // inserts the new tag id within the preorder sequence of tags\r
 \r