{"nwo":"CanonicalLtd\/react-native","sha":"98e0ce38cdcb8c489a064c436a353be754e95f89","path":"JSCLegacyProfiler\/smap.py","language":"python","identifier":"_parse_vlq","parameters":"(segment)","argument_list":"","return_statement":"return values","docstring":"Parse a string of VLQ-encoded data.\n\n Returns:\n a list of integers.","docstring_summary":"Parse a string of VLQ-encoded data.","docstring_tokens":["Parse","a","string","of","VLQ","-","encoded","data","."],"function":"def _parse_vlq(segment):\n \"\"\"Parse a string of VLQ-encoded data.\n\n Returns:\n a list of integers.\n \"\"\"\n\n values = []\n\n cur, shift = 0, 0\n for c in segment:\n val = B64[c]\n # Each character is 6 bits:\n # 5 of value and the high bit is the continuation.\n val, cont = val & 0b11111, val >> 5\n cur += val << shift\n shift += 5\n\n if not cont:\n # The low bit of the unpacked value is the sign.\n cur, sign = cur >> 1, cur & 1\n if sign:\n cur = -cur\n values.append(cur)\n cur, shift = 0, 0\n\n if cur or shift:\n raise Exception('leftover cur\/shift in vlq decode')\n\n return values","function_tokens":["def","_parse_vlq","(","segment",")",":","values","=","[","]","cur",",","shift","=","0",",","0","for","c","in","segment",":","val","=","B64","[","c","]","# Each character is 6 bits:","# 5 of value and the high bit is the continuation.","val",",","cont","=","val","&","0b11111",",","val",">>","5","cur","+=","val","<<","shift","shift","+=","5","if","not","cont",":","# The low bit of the unpacked value is the sign.","cur",",","sign","=","cur",">>","1",",","cur","&","1","if","sign",":","cur","=","-","cur","values",".","append","(","cur",")","cur",",","shift","=","0",",","0","if","cur","or","shift",":","raise","Exception","(","'leftover cur\/shift in vlq decode'",")","return","values"],"url":"https:\/\/github.com\/CanonicalLtd\/react-native\/blob\/98e0ce38cdcb8c489a064c436a353be754e95f89\/JSCLegacyProfiler\/smap.py#L259-L288"} {"nwo":"CanonicalLtd\/react-native","sha":"98e0ce38cdcb8c489a064c436a353be754e95f89","path":"JSCLegacyProfiler\/smap.py","language":"python","identifier":"_parse_smap","parameters":"(file)","argument_list":"","return_statement":"","docstring":"Given a file-like object, yield SmapState()s as they are read from it.","docstring_summary":"Given a file-like object, yield SmapState()s as they are read from it.","docstring_tokens":["Given","a","file","-","like","object","yield","SmapState","()","s","as","they","are","read","from","it","."],"function":"def _parse_smap(file):\n \"\"\"Given a file-like object, yield SmapState()s as they are read from it.\"\"\"\n\n smap = json.load(file)\n sources = smap['sources']\n names = smap['names']\n mappings = smap['mappings']\n lines = mappings.split(';')\n\n dst_col, src_id, src_line, src_col, name_id = 0, 0, 0, 0, 0\n for dst_line, line in enumerate(lines):\n segments = line.split(',')\n dst_col = 0\n for segment in segments:\n if not segment:\n continue\n parsed = _parse_vlq(segment)\n dst_col += parsed[0]\n\n src = None\n name = None\n if len(parsed) > 1:\n src_id += parsed[1]\n src = sources[src_id]\n src_line += parsed[2]\n src_col += parsed[3]\n\n if len(parsed) > 4:\n name_id += parsed[4]\n name = names[name_id]\n\n assert dst_line >= 0\n assert dst_col >= 0\n assert src_line >= 0\n assert src_col >= 0\n\n yield SmapState(dst_line, dst_col, src, src_line, src_col, name)","function_tokens":["def","_parse_smap","(","file",")",":","smap","=","json",".","load","(","file",")","sources","=","smap","[","'sources'","]","names","=","smap","[","'names'","]","mappings","=","smap","[","'mappings'","]","lines","=","mappings",".","split","(","';'",")","dst_col",",","src_id",",","src_line",",","src_col",",","name_id","=","0",",","0",",","0",",","0",",","0","for","dst_line",",","line","in","enumerate","(","lines",")",":","segments","=","line",".","split","(","','",")","dst_col","=","0","for","segment","in","segments",":","if","not","segment",":","continue","parsed","=","_parse_vlq","(","segment",")","dst_col","+=","parsed","[","0","]","src","=","None","name","=","None","if","len","(","parsed",")",">","1",":","src_id","+=","parsed","[","1","]","src","=","sources","[","src_id","]","src_line","+=","parsed","[","2","]","src_col","+=","parsed","[","3","]","if","len","(","parsed",")",">","4",":","name_id","+=","parsed","[","4","]","name","=","names","[","name_id","]","assert","dst_line",">=","0","assert","dst_col",">=","0","assert","src_line",">=","0","assert","src_col",">=","0","yield","SmapState","(","dst_line",",","dst_col",",","src",",","src_line",",","src_col",",","name",")"],"url":"https:\/\/github.com\/CanonicalLtd\/react-native\/blob\/98e0ce38cdcb8c489a064c436a353be754e95f89\/JSCLegacyProfiler\/smap.py#L291-L327"}