mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-11-04 05:19:11 +00:00 
			
		
		
		
	Make IdString::begins_width/ends_with take std::string_view so we avoid a strlen when the parameter is a string constant
This commit is contained in:
		
							parent
							
								
									f6fb423ee8
								
							
						
					
					
						commit
						f7ac724ea9
					
				
					 1 changed files with 7 additions and 8 deletions
				
			
		| 
						 | 
					@ -404,16 +404,15 @@ struct RTLIL::IdString
 | 
				
			||||||
		return strncmp(c_str()+pos, s, len);
 | 
							return strncmp(c_str()+pos, s, len);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bool begins_with(const char* prefix) const {
 | 
						bool begins_with(std::string_view prefix) const {
 | 
				
			||||||
		size_t len = strlen(prefix);
 | 
							if (size() < prefix.size()) return false;
 | 
				
			||||||
		if (size() < len) return false;
 | 
							return compare(0, prefix.size(), prefix.data()) == 0;
 | 
				
			||||||
		return compare(0, len, prefix) == 0;
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bool ends_with(const char* suffix) const {
 | 
						bool ends_with(std::string_view suffix) const {
 | 
				
			||||||
		size_t len = strlen(suffix);
 | 
							size_t sz = size();
 | 
				
			||||||
		if (size() < len) return false;
 | 
							if (sz < suffix.size()) return false;
 | 
				
			||||||
		return compare(size()-len, len, suffix) == 0;
 | 
							return compare(sz - suffix.size(), suffix.size(), suffix.data()) == 0;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bool contains(const char* str) const {
 | 
						bool contains(const char* str) const {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue