/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/_static_tuple_c.c

  • Committer: Gustav Hartvigsson
  • Date: 2021-01-09 21:36:27 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210109213627-h1xwcutzy9m7a99b
Added 'Case Preserving Working Tree Use Cases' from Canonical Wiki

* Addod a page from the Canonical Bazaar wiki
  with information on the scmeatics of case
  perserving filesystems an a case insensitive
  filesystem works.
  
  * Needs re-work, but this will do as it is the
    same inforamoton as what was on the linked
    page in the currint documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
320
320
    return result;
321
321
}
322
322
 
 
323
/* adapted from tuplehash(), is the specific hash value considered
 
324
 * 'stable'?
 
325
 */
 
326
 
 
327
#if PY_MAJOR_VERSION > 3 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 8)
 
328
/* Hash for tuples. This is a slightly simplified version of the xxHash
 
329
   non-cryptographic hash:
 
330
   - we do not use any parallellism, there is only 1 accumulator.
 
331
   - we drop the final mixing since this is just a permutation of the
 
332
     output space: it does not help against collisions.
 
333
   - at the end, we mangle the length with a single constant.
 
334
   For the xxHash specification, see
 
335
   https://github.com/Cyan4973/xxHash/blob/master/doc/xxhash_spec.md
 
336
 
 
337
   Below are the official constants from the xxHash specification. Optimizing
 
338
   compilers should emit a single "rotate" instruction for the
 
339
   _PyHASH_XXROTATE() expansion. If that doesn't happen for some important
 
340
   platform, the macro could be changed to expand to a platform-specific rotate
 
341
   spelling instead.
 
342
*/
 
343
#if SIZEOF_PY_UHASH_T > 4
 
344
#define _PyHASH_XXPRIME_1 ((Py_uhash_t)11400714785074694791ULL)
 
345
#define _PyHASH_XXPRIME_2 ((Py_uhash_t)14029467366897019727ULL)
 
346
#define _PyHASH_XXPRIME_5 ((Py_uhash_t)2870177450012600261ULL)
 
347
#define _PyHASH_XXROTATE(x) ((x << 31) | (x >> 33))  /* Rotate left 31 bits */
 
348
#else
 
349
#define _PyHASH_XXPRIME_1 ((Py_uhash_t)2654435761UL)
 
350
#define _PyHASH_XXPRIME_2 ((Py_uhash_t)2246822519UL)
 
351
#define _PyHASH_XXPRIME_5 ((Py_uhash_t)374761393UL)
 
352
#define _PyHASH_XXROTATE(x) ((x << 13) | (x >> 19))  /* Rotate left 13 bits */
 
353
#endif
 
354
 
 
355
/* Tests have shown that it's not worth to cache the hash value, see
 
356
   https://bugs.python.org/issue9685 */
 
357
static Py_hash_t
 
358
StaticTuple_hash(StaticTuple *self)
 
359
{
 
360
    Py_ssize_t i, len = self->size;
 
361
    PyObject **item = self->items;
 
362
 
 
363
#if STATIC_TUPLE_HAS_HASH
 
364
    if (self->hash != -1) {
 
365
        return self->hash;
 
366
    }
 
367
#endif
 
368
 
 
369
    Py_uhash_t acc = _PyHASH_XXPRIME_5;
 
370
    for (i = 0; i < len; i++) {
 
371
        Py_uhash_t lane = PyObject_Hash(item[i]);
 
372
        if (lane == (Py_uhash_t)-1) {
 
373
            return -1;
 
374
        }
 
375
        acc += lane * _PyHASH_XXPRIME_2;
 
376
        acc = _PyHASH_XXROTATE(acc);
 
377
        acc *= _PyHASH_XXPRIME_1;
 
378
    }
 
379
 
 
380
    /* Add input length, mangled to keep the historical value of hash(()). */
 
381
    acc += len ^ (_PyHASH_XXPRIME_5 ^ 3527539UL);
 
382
 
 
383
    if (acc == (Py_uhash_t)-1) {
 
384
        acc = 1546275796;
 
385
    }
 
386
 
 
387
#if STATIC_TUPLE_HAS_HASH
 
388
    self->hash = acc;
 
389
#endif
 
390
    return acc;
 
391
}
 
392
 
 
393
 
 
394
#else
323
395
static long
324
396
StaticTuple_hash(StaticTuple *self)
325
397
{
357
429
#endif
358
430
    return x;
359
431
}
 
432
#endif
360
433
 
361
434
static PyObject *
362
435
StaticTuple_richcompare_to_tuple(StaticTuple *v, PyObject *wt, int op)