Faster approach to checking for an all-zero buffer in C?

后端 未结 20 2404
孤独总比滥情好
孤独总比滥情好 2020-12-03 05:33

I am searching for a faster method of accomplishing this:

int is_empty(char * buf, int size) 
{
    int i;
    for(i = 0; i < size; i++) {
        if(buf[         


        
20条回答
  •  感动是毒
    2020-12-03 05:56

    int is_empty(char * buf, int size) 
    {
        int i, content=0;  
        for(i = 0; !content && i < size; i++)    
        {  
            content=content | buf(i);       // bitwise or  
        }  
        return (content==0);  
    }
    

提交回复
热议问题