scottmac / opengraph

Helper class for accessing the OpenGraph Protocol
463 stars 151 forks source link

No need to scan all string to find starting substring match #32

Open vvendigo opened 9 years ago

vvendigo commented 9 years ago

No need to scan all string to find starting substring match

AramZS commented 8 years ago

Hi @vvendigo - I'm maintaining this project from upstream, can you tell me why this method would be preferred? If there is a good reason, I'll merge it in.

vvendigo commented 8 years ago

Hi! This is just a petty optimization. Strpos() scans all the string in vain if there is no 'og:' in it. Strncmp() compares just first N chars to given string. In the first case === 0 means that string was found at position 0, in the later 0 means that strings are equal. So condition result is the same.