fdd15dd4ea30b1f9f319ff22bc2858f00c7aa8ed angie Fri Jul 10 13:49:45 2020 -0700 strtod is faster than sscanf; when parsing a tree with ~61k node lengths, it makes a difference of >3s. diff --git src/lib/phyloTree.c src/lib/phyloTree.c index 6796a15..cf25448 100644 --- src/lib/phyloTree.c +++ src/lib/phyloTree.c @@ -102,31 +102,36 @@ { char val; val = *ptr; *ptr = 0; pName->name = cloneString(start); pName->name = trimSpaces(pName->name); pName->name = unescapeNewark(pName->name); *ptr = val; } /* is there some branch length info */ if (*ptr == ':') { ptr++; - sscanf(ptr, "%lg", &pName->length); + char *lStart = ptr; + while (isdigit(*ptr) || *ptr == '.' || *ptr == 'e' || *ptr == 'E' || *ptr == '+' || *ptr == '-') + ptr++; + int lSize = ptr - lStart; + if (lSize) + pName->length = strtod(lStart, NULL); while ((*ptr != '[') && (*ptr != ')') && (*ptr != ',') && (*ptr != ';')) ptr++; } *ptrPtr = ptr; return pName; } static struct phyloTree *newEdge(struct phyloTree *parent, struct phyloTree *child) { parent->numEdges++; if (parent->numEdges > parent->allocedEdges) {