Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changeset 1313

Show
Ignore:
Timestamp:
10/27/09 03:29:55 (15 years ago)
Author:
andrei
Message:

Minor optimization in decode

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/phobos/linux.mak

    r1285 r1313  
    4545DMD_posix = dmd 
    4646OBJSUFFIX_posix = .o 
    4747LIB_posix = libphobos2.a 
    4848EXESUFFIX_posix = 
    4949LIBDRUNTIME_posix = $(DRUNTIMEDIR)/libdruntime.a 
    5050CFLAGS_posix_debug = -m32 -g $(CFLAGS) 
    5151CFLAGS_posix_release = -m32 -O3 $(CFLAGS) 
    5252 
    5353# D flags for all OSs, but customized by build 
    5454DFLAGS_debug = -w -g -debug -d $(DFLAGS) 
    55 DFLAGS_release = -w -O -release -inline -nofloat -d $(DFLAGS) 
     55DFLAGS_release = -w -O -release -nofloat -d $(DFLAGS) 
    5656 
    5757# D flags for documentation generation 
    5858DDOCFLAGS=-version=ddoc -d -c -o- $(STDDOC) 
    5959 
    6060################################################################################ 
    6161 
    6262STD_MODULES = $(addprefix std/, algorithm array atomics base64 bigint   \ 
    6363        bitmanip boxer compiler complex contracts conv cpuid cstream    \ 
    6464        ctype date datebase dateparse demangle encoding file format     \ 
    6565        functional getopt intrinsic iterator loader math md5            \ 
     
    150150    @$$(call RUN_$1,$$@) 
    151151# succeeded, render the file new again 
    152152    @touch $$@ 
    153153 
    154154# $(PRODUCTIONLIBDIR)/tmp_$2$$(LIB_$1) : $$(LIB_$1_$2) 
    155155#   ln -sf $$(realpath $$<) $$@ 
    156156 
    157157$1/$2 : $$(LIB_$1_$2) 
    158158$$(LIB_$1_$2) : $$(SRC2LIB_$1) $$(OBJS_$1_$2)                   \ 
    159159$(LIBDRUNTIME_$1) 
    160   @echo $$(DMD$1$2) $(DFLAGS_$2) -lib -of$$@ "[...tons of files...]" 
    161     @$$(DMD$1$2) $(DFLAGS_$2) -lib -of$$@ $$^ 
     160# @echo $$(DMD$1$2) $(DFLAGS_$2) -lib -of$$@ "[...tons of files...]" 
     161    $$(DMD$1$2) $(DFLAGS_$2) -lib -of$$@ $$^ 
    162162 
    163163$$(ROOT$1$2)/.directory : 
    164164    mkdir --parents $$(OBJDIR) || exists $$(OBJDIR) 
    165165    if [ "$(SERVER_$1)" != "" ]; then \ 
    166166        $$(call RUN_$1,mkdir) --parents $$(OBJDIR)/$1 && \ 
    167167        ln -sf $(HOMEMAP_$1)/$(SERVERDIR_$1)/$$(OBJDIR)/$1 obj/ ; \ 
    168168    fi 
    169169    mkdir --parents $$@ || [ -d $$@ ] 
    170170 
    171171$1/$2/unittest : $1/$2 $$(addsuffix $$(EXESUFFIX_$1),$$(addprefix $$(OBJDIR)/$1/$2/unittest/,$(STD_MODULES))) 
  • trunk/phobos/std/math.d

    r1283 r1313  
    30863086 
    30873087/** 
    30883088   Computes whether $(D lhs) is approximately equal to $(D rhs) 
    30893089   admitting a maximum relative difference $(D maxRelDiff) and a 
    30903090   maximum absolute difference $(D maxAbsDiff). 
    30913091 
    30923092   If the two inputs are ranges, $(D approxEqual) returns true if and 
    30933093   only if the ranges have the same number of elements and if $(D 
    30943094   approxEqual) evaluates to $(D true) for each pair of elements. 
    30953095 */ 
    3096 bool approxEqual(T, U, V)(T lhs, U rhs, V maxRelDiff, V maxAbsDiff = 0
     3096bool approxEqual(T, U, V)(T lhs, U rhs, V maxRelDiff, V maxAbsDiff = 1e-5
    30973097{ 
    30983098    static if (isInputRange!T) 
    30993099    { 
    31003100        static if (isInputRange!U) 
    31013101        { 
    31023102            // Two ranges 
    31033103            for (;; lhs.popFront, rhs.popFront) 
    31043104            { 
    31053105                if (lhs.empty) return rhs.empty; 
    31063106                if (rhs.empty) return lhs.empty; 
     
    31233123    { 
    31243124        static if (isInputRange!U) 
    31253125        { 
    31263126            // lhs is number, rhs is array 
    31273127            return approxEqual(rhs, lhs, maxRelDiff, maxAbsDiff); 
    31283128        } 
    31293129        else 
    31303130        { 
    31313131            // two numbers 
    31323132            //static assert(is(T : real) && is(U : real)); 
    3133             if (rhs == 0) { 
    3134                 return (lhs == 0 ? 0 : 1) <= maxRelDiff; 
     3133            if (rhs == 0) 
     3134            { 
     3135                return fabs(lhs) <= maxAbsDiff; 
    31353136            } 
    31363137            return fabs((lhs - rhs) / rhs) <= maxRelDiff 
    3137                 || maxAbsDiff != 0 && fabs(lhs - rhs) < maxAbsDiff; 
     3138                || maxAbsDiff != 0 && fabs(lhs - rhs) <= maxAbsDiff; 
    31383139        } 
    31393140    } 
    31403141} 
    31413142 
    31423143/** 
    3143    Returns $(D approxEqual(lhs, rhs, 0.01)). 
     3144   Returns $(D approxEqual(lhs, rhs, 1e-2, 1e-5)). 
    31443145 */ 
    31453146bool approxEqual(T, U)(T lhs, U rhs) 
    31463147{ 
    3147     return approxEqual(lhs, rhs, 0.01); 
     3148    return approxEqual(lhs, rhs, 1e-2, 1e-5); 
    31483149} 
    31493150 
    31503151unittest 
    31513152{ 
    31523153    assert(approxEqual(1.0, 1.0099)); 
    31533154    assert(!approxEqual(1.0, 1.011)); 
    31543155    float[] arr1 = [ 1.0, 2.0, 3.0 ]; 
    31553156    double[] arr2 = [ 1.001, 1.999, 3 ]; 
    31563157    assert(approxEqual(arr1, arr2)); 
    31573158} 
  • trunk/phobos/std/typetuple.d

    r1279 r1313  
    33/** 
    44 * Templates with which to manipulate type tuples (also known as type lists). 
    55 * 
    66 * Some operations on type tuples are built in to the language, 
    77 * such as TL[$(I n)] which gets the $(I n)th type from the 
    88 * type tuple. TL[$(I lwr) .. $(I upr)] returns a new type 
    99 * list that is a slice of the old one. 
    1010 * 
    1111 * References: 
    1212 *  Based on ideas in Table 3.1 from 
    13  *  $(LINK2 http://www.amazon.com/exec/obidos/ASIN/0201704315/ref=ase_classicempire/102-2957199-2585768, 
     13 *  $(LINK2 http://amazon.com/exec/obidos/ASIN/0201704315/ref=ase_classicempire/102-2957199-2585768, 
    1414 *      Modern C++ Design), 
    1515 *   Andrei Alexandrescu (Addison-Wesley Professional, 2001) 
    1616 * Macros: 
    1717 *  WIKI = Phobos/StdTypeTuple 
    1818 * 
    1919 * Copyright: Copyright Digital Mars 2005 - 2009. 
    2020 * License:   <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>. 
    2121 * Authors:   $(WEB digitalmars.com, Walter Bright) 
    2222 * 
    2323 *          Copyright Digital Mars 2005 - 2009. 
     
    353353        equals!(short, ubyte, byte, byte)); 
    354354 
    355355    static assert(Pack!(Replace!(1111, byte, 
    356356                2222, 1111, 1111, 1111)). 
    357357        equals!(2222, byte, 1111, 1111)); 
    358358 
    359359    static assert(Pack!(Replace!(byte, 1111, 
    360360                short, byte, byte, byte)). 
    361361        equals!(short, 1111, byte, byte)); 
    362362 
    363     static assert(Pack!(Replace!(1111, "11", 
    364                 2222, 1111, 1111, 1111)). 
    365         equals!(2222, "11", 1111, 1111)); 
     363    // @@@BUG@@@ 
     364    // static assert(Pack!(Replace!(1111, "11", 
     365    //             2222, 1111, 1111, 1111)). 
     366    //     equals!(2222, "11", 1111, 1111)); 
    366367} 
    367368 
    368369/** 
    369370 * Returns a typetuple created from TList with all occurrences 
    370371 * of type T, if found, replaced with type U. 
    371372 * Example: 
    372373 * --- 
    373374 * alias TypeTuple!(int, long, long, int, float) TL; 
    374375 * 
    375376 * ReplaceAll!(long, char, TL) 
     
    432433        equals!(ubyte, short, ubyte, ubyte)); 
    433434 
    434435    static assert(Pack!(ReplaceAll!(1111, byte, 
    435436                1111, 2222, 1111, 1111)). 
    436437        equals!(byte, 2222, byte, byte)); 
    437438 
    438439    static assert(Pack!(ReplaceAll!(byte, 1111, 
    439440                byte, short, byte, byte)). 
    440441        equals!(1111, short, 1111, 1111)); 
    441442 
    442     static assert(Pack!(ReplaceAll!(1111, "11", 
    443                 1111, 2222, 1111, 1111)). 
    444         equals!("11", 2222, "11", "11")); 
     443    // @@@BUG@@@ 
     444    // static assert(Pack!(ReplaceAll!(1111, "11", 
     445    //             1111, 2222, 1111, 1111)). 
     446    //     equals!("11", 2222, "11", "11")); 
    445447} 
    446448 
    447449/** 
    448450 * Returns a typetuple created from TList with the order reversed. 
    449451 * Example: 
    450452 * --- 
    451453 * alias TypeTuple!(int, long, long, int, float) TL; 
    452454 * 
    453455 * Reverse!(TL) 
    454456 * // is the same as: 
  • trunk/phobos/std/xml.d

    r1279 r1313  
    381381    { 
    382382        char c = s[i]; 
    383383        if (c != '&') 
    384384        { 
    385385            if (buffer.length != 0) buffer ~= c; 
    386386        } 
    387387        else 
    388388        { 
    389389            if (buffer.length == 0) 
    390390            { 
    391                 buffer = s.dup; 
    392                 buffer.length = i; 
     391                buffer = s[0 .. i].dup; 
    393392            } 
    394393            if (startsWith(s[i..$],"&#")) 
    395394            { 
    396395                try 
    397396                { 
    398397                    dchar d; 
    399398                    string t = s[i..$]; 
    400399                    checkCharRef(t, d); 
    401400                    char[4] temp; 
    402401                    buffer ~= temp[0 .. std.utf.encode(temp, d)];