Changeset 279733d


Ignore:
Timestamp:
03/12/08 14:40:30 (4 years ago)
Author:
Tomash Brechko <tomash.brechko@…>
Branches:
master, ketama-compat
Children:
b1cbae
Parents:
272c52
git-author:
Tomash Brechko <tomash.brechko@…> (03/12/08 14:09:36)
git-committer:
Tomash Brechko <tomash.brechko@…> (03/12/08 14:40:30)
Message:

Make compute_crc32_add() more optimal.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/gencrc32.pl

    rcd76f9 r279733d  
    11#! /usr/bin/perl 
    22# 
    3 # Copyright (C) 2007 Tomash Brechko.  All rights reserved. 
     3# Copyright (C) 2007-2008 Tomash Brechko.  All rights reserved. 
    44# 
    55# This program is free software; you can redistribute it and/or modify 
     
    7070 
    7171 
    72 static const unsigned int crc32lookup[256] = { 
     72const unsigned int crc32lookup[256] = { 
    7373  $table 
    7474}; 
    75  
    76  
    77 unsigned int 
    78 compute_crc32_add(unsigned int crc32, const char *s, size_t len) 
    79 { 
    80   const char *end = s + len; 
    81  
    82   crc32 = ~crc32; 
    83  
    84   while (s < end) 
    85     { 
    86       unsigned int index = (crc32 ^ (unsigned char) *s) & 0x000000ffU; 
    87       crc32 = (crc32 >> 8) ^ crc32lookup[index]; 
    88       ++s; 
    89     } 
    90  
    91   return (~crc32); 
    92 } 
    9375EOF 
    9476 
     
    11294 
    11395 
    114 extern 
    115 unsigned int 
    116 compute_crc32_add(unsigned int crc32, const char *s, size_t len); 
     96extern const unsigned int crc32lookup[]; 
    11797 
     98 
     99#define compute_crc32(s, l)                                      \\ 
     100  compute_crc32_add(@{[ sprintf("0x%08xU", $init) ]}, (s), (l)) 
    118101 
    119102static inline 
    120103unsigned int 
    121 compute_crc32(const char *s, size_t len) 
     104compute_crc32_add(unsigned int crc32, const char *s, size_t len) 
    122105{ 
    123   return compute_crc32_add(@{[ sprintf("0x%08xU", $init) ]}, s, len); 
     106  const char *end = s + len; 
     107 
     108  crc32 = ~crc32; 
     109 
     110  while (s < end) 
     111    { 
     112      unsigned int index = (crc32 ^ (unsigned char) *s) & 0x000000ffU; 
     113      crc32 = (crc32 >> 8) ^ crc32lookup[index]; 
     114      ++s; 
     115    } 
     116 
     117  return (~crc32); 
    124118} 
    125119 
Note: See TracChangeset for help on using the changeset viewer.